Change ComboBox border color

This commit is contained in:
2023-03-13 18:13:41 +01:00
parent a17210e93c
commit 568eedcdf3
2 changed files with 41 additions and 6 deletions

View File

@ -6,19 +6,43 @@ using System.Windows.Media;
using System.Windows;
using System.Windows.Controls;
using System.Diagnostics;
using System.Windows.Controls.Primitives;
namespace WGneu.Helpers {
public static class Utils {
public static void SetInputChanged(Control input) {
input.BorderBrush = Brushes.Orange;
var brush = Brushes.Orange;
if (input is ComboBox cb) {
var border = GetComboBoxBorder(cb);
if (border != null)
border.BorderBrush = brush;
} else {
input.BorderBrush = brush;
}
}
public static void SetInputInvalid(Control input) {
input.BorderBrush = Brushes.Red;
var brush = Brushes.Red;
if (input is ComboBox cb) {
var border = GetComboBoxBorder(cb);
if (border != null)
border.BorderBrush = brush;
} else {
input.BorderBrush = brush;
}
}
public static void ClearInputState(Control input) {
input.ClearValue(Control.BorderBrushProperty);
if (input is ComboBox cb) {
GetComboBoxBorder(cb)?.ClearValue(Border.BorderBrushProperty);
} else {
input.ClearValue(Control.BorderBrushProperty);
}
}
private static Border? GetComboBoxBorder(ComboBox cb) {
var toggleButton = cb.Template.FindName("toggleButton", cb) as ToggleButton;
return toggleButton?.Template.FindName("templateRoot", toggleButton) as Border;
}
public static IEnumerable<T> FindVisualChilds<T>(DependencyObject depObj) where T : DependencyObject {