Change ComboBox border color
This commit is contained in:
@ -6,20 +6,44 @@ using System.Windows.Media;
|
|||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Windows.Controls.Primitives;
|
||||||
|
|
||||||
namespace WGneu.Helpers {
|
namespace WGneu.Helpers {
|
||||||
public static class Utils {
|
public static class Utils {
|
||||||
public static void SetInputChanged(Control input) {
|
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) {
|
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) {
|
public static void ClearInputState(Control input) {
|
||||||
|
if (input is ComboBox cb) {
|
||||||
|
GetComboBoxBorder(cb)?.ClearValue(Border.BorderBrushProperty);
|
||||||
|
} else {
|
||||||
input.ClearValue(Control.BorderBrushProperty);
|
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 {
|
public static IEnumerable<T> FindVisualChilds<T>(DependencyObject depObj) where T : DependencyObject {
|
||||||
if (depObj == null)
|
if (depObj == null)
|
||||||
|
@ -114,6 +114,8 @@ namespace WGneu.Windows {
|
|||||||
EntryDateInput.Text = DateTime.Now.ToString("dd.MM.yyyy");
|
EntryDateInput.Text = DateTime.Now.ToString("dd.MM.yyyy");
|
||||||
if (Context.Branches.Count() == 1)
|
if (Context.Branches.Count() == 1)
|
||||||
BranchInput.SelectedItem = Context.Branches.First();
|
BranchInput.SelectedItem = Context.Branches.First();
|
||||||
|
ActiveInput.IsChecked = true;
|
||||||
|
ContactPostInput.IsChecked = true;
|
||||||
FillOriginalValues();
|
FillOriginalValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -420,8 +422,11 @@ namespace WGneu.Windows {
|
|||||||
tb.Text = " ";
|
tb.Text = " ";
|
||||||
tb.Text = "";
|
tb.Text = "";
|
||||||
}
|
}
|
||||||
foreach (var cb in Utils.FindVisualChilds<ComboBox>(this, ExemptInputs))
|
foreach (var cb in Utils.FindVisualChilds<ComboBox>(this, ExemptInputs)) {
|
||||||
cb.SelectedItem = null;
|
cb.SelectedItem = null;
|
||||||
|
if (cb.ItemsSource != null)
|
||||||
|
Utils.SetInputInvalid(cb);
|
||||||
|
}
|
||||||
foreach (var cb in Utils.FindVisualChilds<CheckBox>(this, ExemptInputs))
|
foreach (var cb in Utils.FindVisualChilds<CheckBox>(this, ExemptInputs))
|
||||||
cb.IsChecked = false;
|
cb.IsChecked = false;
|
||||||
foreach (var rb in Utils.FindVisualChilds<RadioButton>(this, ExemptInputs))
|
foreach (var rb in Utils.FindVisualChilds<RadioButton>(this, ExemptInputs))
|
||||||
@ -472,6 +477,11 @@ namespace WGneu.Windows {
|
|||||||
ortInput.ItemsSource = null;
|
ortInput.ItemsSource = null;
|
||||||
}
|
}
|
||||||
ortInput.SelectedItem = null;
|
ortInput.SelectedItem = null;
|
||||||
|
if (ortInput.ItemsSource != null) {
|
||||||
|
Utils.SetInputInvalid(ortInput);
|
||||||
|
} else {
|
||||||
|
Utils.ClearInputState(ortInput);
|
||||||
|
}
|
||||||
Valid[plzInput] = optional || (ortInput.ItemsSource != null);
|
Valid[plzInput] = optional || (ortInput.ItemsSource != null);
|
||||||
UpdateButtons();
|
UpdateButtons();
|
||||||
}
|
}
|
||||||
@ -545,8 +555,9 @@ namespace WGneu.Windows {
|
|||||||
|
|
||||||
private void ComboBox_SelectionChanged(object sender, RoutedEventArgs evt) {
|
private void ComboBox_SelectionChanged(object sender, RoutedEventArgs evt) {
|
||||||
var input = (ComboBox)sender;
|
var input = (ComboBox)sender;
|
||||||
if (InputHasChanged(input)) {
|
if (input.ItemsSource != null && input.SelectedItem == null) {
|
||||||
// TODO not working
|
Utils.SetInputInvalid(input);
|
||||||
|
} else if (InputHasChanged(input)) {
|
||||||
Utils.SetInputChanged(input);
|
Utils.SetInputChanged(input);
|
||||||
} else {
|
} else {
|
||||||
Utils.ClearInputState(input);
|
Utils.ClearInputState(input);
|
||||||
|
Reference in New Issue
Block a user