45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Media;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
|
|
namespace WGneu {
|
|
class Utils {
|
|
public static void SetInputChanged(Control input) {
|
|
input.BorderBrush = Brushes.Orange;
|
|
}
|
|
|
|
public static void SetInputInvalid(Control input) {
|
|
input.BorderBrush = Brushes.Red;
|
|
}
|
|
|
|
public static void ClearInputState(Control input) {
|
|
input.ClearValue(Control.BorderBrushProperty);
|
|
}
|
|
|
|
public static IEnumerable<T> FindVisualChilds<T>(DependencyObject depObj) where T : DependencyObject {
|
|
if (depObj == null)
|
|
yield return (T)Enumerable.Empty<T>();
|
|
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++) {
|
|
DependencyObject ithChild = VisualTreeHelper.GetChild(depObj, i);
|
|
if (ithChild == null)
|
|
continue;
|
|
if (ithChild is T t)
|
|
yield return t;
|
|
foreach (T childOfChild in FindVisualChilds<T>(ithChild))
|
|
yield return childOfChild;
|
|
}
|
|
}
|
|
|
|
public static int Modulo(string a, int b) {
|
|
if (!a.All(char.IsDigit))
|
|
throw new ArgumentException("First argument has to be a decimal string");
|
|
return a.Select(ch => ch - '0').Aggregate((sum, n) => (sum * 10 + n) % b);
|
|
}
|
|
}
|
|
}
|