diff options
| author | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 15:29:41 +0000 |
|---|---|---|
| committer | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 15:29:41 +0000 |
| commit | 225aa1499e37faf9d38257caabbadc68d78b427e (patch) | |
| tree | 102bb7a40c58595348ae9d3c7076201759fe0720 /Decompiler/Gestor.Application.Helpers/ViewHelper.cs | |
| parent | 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (diff) | |
| download | gestor-225aa1499e37faf9d38257caabbadc68d78b427e.tar.gz gestor-225aa1499e37faf9d38257caabbadc68d78b427e.zip | |
decompiler.com
Diffstat (limited to 'Decompiler/Gestor.Application.Helpers/ViewHelper.cs')
| -rw-r--r-- | Decompiler/Gestor.Application.Helpers/ViewHelper.cs | 878 |
1 files changed, 878 insertions, 0 deletions
diff --git a/Decompiler/Gestor.Application.Helpers/ViewHelper.cs b/Decompiler/Gestor.Application.Helpers/ViewHelper.cs new file mode 100644 index 0000000..f4c38e6 --- /dev/null +++ b/Decompiler/Gestor.Application.Helpers/ViewHelper.cs @@ -0,0 +1,878 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.Dynamic; +using System.Linq; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; +using System.Windows.Data; +using System.Windows.Media; +using CurrencyTextBoxControl; +using Gestor.Application.Componentes; +using Gestor.Model.Helper; +using Xceed.Wpf.Toolkit; +using Xceed.Wpf.Toolkit.Primitives; + +namespace Gestor.Application.Helpers; + +public static class ViewHelper +{ + [CompilerGenerated] + private sealed class _003CFindAncestor_003Ed__11<T> : IEnumerable<T>, IEnumerable, IEnumerator<T>, IDisposable, IEnumerator where T : DependencyObject + { + private int _003C_003E1__state; + + private T _003C_003E2__current; + + private int _003C_003El__initialThreadId; + + private DependencyObject dependencyObject; + + public DependencyObject _003C_003E3__dependencyObject; + + private DependencyObject _003CparentReference_003E5__2; + + T IEnumerator<T>.Current + { + [DebuggerHidden] + get + { + return _003C_003E2__current; + } + } + + object IEnumerator.Current + { + [DebuggerHidden] + get + { + return _003C_003E2__current; + } + } + + [DebuggerHidden] + public _003CFindAncestor_003Ed__11(int _003C_003E1__state) + { + this._003C_003E1__state = _003C_003E1__state; + _003C_003El__initialThreadId = Environment.CurrentManagedThreadId; + } + + [DebuggerHidden] + void IDisposable.Dispose() + { + _003CparentReference_003E5__2 = null; + _003C_003E1__state = -2; + } + + private bool MoveNext() + { + int num = _003C_003E1__state; + if (num != 0) + { + if (num != 1) + { + return false; + } + _003C_003E1__state = -1; + goto IL_005a; + } + _003C_003E1__state = -1; + _003CparentReference_003E5__2 = VisualTreeHelper.GetParent(dependencyObject); + goto IL_006b; + IL_005a: + _003CparentReference_003E5__2 = VisualTreeHelper.GetParent(_003CparentReference_003E5__2); + goto IL_006b; + IL_006b: + if (_003CparentReference_003E5__2 == null) + { + return false; + } + DependencyObject obj = _003CparentReference_003E5__2; + T val = (T)(object)((obj is T) ? obj : null); + if (val != null) + { + _003C_003E2__current = val; + _003C_003E1__state = 1; + return true; + } + goto IL_005a; + } + + bool IEnumerator.MoveNext() + { + //ILSpy generated this explicit interface implementation from .override directive in MoveNext + return this.MoveNext(); + } + + [DebuggerHidden] + void IEnumerator.Reset() + { + throw new NotSupportedException(); + } + + [DebuggerHidden] + IEnumerator<T> IEnumerable<T>.GetEnumerator() + { + _003CFindAncestor_003Ed__11<T> _003CFindAncestor_003Ed__; + if (_003C_003E1__state == -2 && _003C_003El__initialThreadId == Environment.CurrentManagedThreadId) + { + _003C_003E1__state = 0; + _003CFindAncestor_003Ed__ = this; + } + else + { + _003CFindAncestor_003Ed__ = new _003CFindAncestor_003Ed__11<T>(0); + } + _003CFindAncestor_003Ed__.dependencyObject = _003C_003E3__dependencyObject; + return _003CFindAncestor_003Ed__; + } + + [DebuggerHidden] + IEnumerator IEnumerable.GetEnumerator() + { + return ((IEnumerable<T>)this).GetEnumerator(); + } + } + + [CompilerGenerated] + private sealed class _003CFindChildren_003Ed__2<T> : IEnumerable<T>, IEnumerable, IEnumerator<T>, IDisposable, IEnumerator where T : DependencyObject + { + private int _003C_003E1__state; + + private T _003C_003E2__current; + + private int _003C_003El__initialThreadId; + + private DependencyObject depObj; + + public DependencyObject _003C_003E3__depObj; + + private IEnumerator _003C_003E7__wrap1; + + private object _003Cchild_003E5__3; + + private IEnumerator<T> _003C_003E7__wrap3; + + T IEnumerator<T>.Current + { + [DebuggerHidden] + get + { + return _003C_003E2__current; + } + } + + object IEnumerator.Current + { + [DebuggerHidden] + get + { + return _003C_003E2__current; + } + } + + [DebuggerHidden] + public _003CFindChildren_003Ed__2(int _003C_003E1__state) + { + this._003C_003E1__state = _003C_003E1__state; + _003C_003El__initialThreadId = Environment.CurrentManagedThreadId; + } + + [DebuggerHidden] + void IDisposable.Dispose() + { + int num = _003C_003E1__state; + if ((uint)(num - -4) <= 1u || (uint)(num - 1) <= 1u) + { + try + { + if (num == -4 || num == 2) + { + try + { + } + finally + { + _003C_003Em__Finally2(); + } + } + } + finally + { + _003C_003Em__Finally1(); + } + } + _003C_003E7__wrap1 = null; + _003Cchild_003E5__3 = null; + _003C_003E7__wrap3 = null; + _003C_003E1__state = -2; + } + + private bool MoveNext() + { + try + { + object obj; + DependencyObject val; + switch (_003C_003E1__state) + { + default: + return false; + case 0: + _003C_003E1__state = -1; + if (depObj == null) + { + return false; + } + _003C_003E7__wrap1 = LogicalTreeHelper.GetChildren(depObj).GetEnumerator(); + _003C_003E1__state = -3; + goto IL_012e; + case 1: + _003C_003E1__state = -3; + goto IL_00be; + case 2: + { + _003C_003E1__state = -4; + goto IL_010d; + } + IL_010d: + if (_003C_003E7__wrap3.MoveNext()) + { + T current = _003C_003E7__wrap3.Current; + _003C_003E2__current = current; + _003C_003E1__state = 2; + return true; + } + _003C_003Em__Finally2(); + _003C_003E7__wrap3 = null; + _003Cchild_003E5__3 = null; + goto IL_012e; + IL_00be: + obj = _003Cchild_003E5__3; + val = (DependencyObject)((obj is DependencyObject) ? obj : null); + _003C_003E7__wrap3 = val.FindChildren<T>().GetEnumerator(); + _003C_003E1__state = -4; + goto IL_010d; + IL_012e: + if (_003C_003E7__wrap1.MoveNext()) + { + _003Cchild_003E5__3 = _003C_003E7__wrap1.Current; + object obj2 = _003Cchild_003E5__3; + T val2 = (T)((obj2 is T) ? obj2 : null); + if (val2 != null) + { + object obj3 = val2; + object obj4 = ((obj3 is ContentControl) ? obj3 : null); + object obj5 = val2; + UserControl val3 = (UserControl)((obj5 is UserControl) ? obj5 : null); + if (obj4 == null || val3 != null) + { + _003C_003E2__current = val2; + _003C_003E1__state = 1; + return true; + } + } + goto IL_00be; + } + _003C_003Em__Finally1(); + _003C_003E7__wrap1 = null; + return false; + } + } + catch + { + //try-fault + ((IDisposable)this).Dispose(); + throw; + } + } + + bool IEnumerator.MoveNext() + { + //ILSpy generated this explicit interface implementation from .override directive in MoveNext + return this.MoveNext(); + } + + private void _003C_003Em__Finally1() + { + _003C_003E1__state = -1; + if (_003C_003E7__wrap1 is IDisposable disposable) + { + disposable.Dispose(); + } + } + + private void _003C_003Em__Finally2() + { + _003C_003E1__state = -3; + if (_003C_003E7__wrap3 != null) + { + _003C_003E7__wrap3.Dispose(); + } + } + + [DebuggerHidden] + void IEnumerator.Reset() + { + throw new NotSupportedException(); + } + + [DebuggerHidden] + IEnumerator<T> IEnumerable<T>.GetEnumerator() + { + _003CFindChildren_003Ed__2<T> _003CFindChildren_003Ed__; + if (_003C_003E1__state == -2 && _003C_003El__initialThreadId == Environment.CurrentManagedThreadId) + { + _003C_003E1__state = 0; + _003CFindChildren_003Ed__ = this; + } + else + { + _003CFindChildren_003Ed__ = new _003CFindChildren_003Ed__2<T>(0); + } + _003CFindChildren_003Ed__.depObj = _003C_003E3__depObj; + return _003CFindChildren_003Ed__; + } + + [DebuggerHidden] + IEnumerator IEnumerable.GetEnumerator() + { + return ((IEnumerable<T>)this).GetEnumerator(); + } + } + + [CompilerGenerated] + private sealed class _003CFindParent_003Ed__3<T> : IEnumerable<T>, IEnumerable, IEnumerator<T>, IDisposable, IEnumerator where T : DependencyObject + { + private int _003C_003E1__state; + + private T _003C_003E2__current; + + private int _003C_003El__initialThreadId; + + private DependencyObject depObj; + + public DependencyObject _003C_003E3__depObj; + + private DependencyObject _003CfirstParent_003E5__2; + + private IEnumerator<T> _003C_003E7__wrap2; + + T IEnumerator<T>.Current + { + [DebuggerHidden] + get + { + return _003C_003E2__current; + } + } + + object IEnumerator.Current + { + [DebuggerHidden] + get + { + return _003C_003E2__current; + } + } + + [DebuggerHidden] + public _003CFindParent_003Ed__3(int _003C_003E1__state) + { + this._003C_003E1__state = _003C_003E1__state; + _003C_003El__initialThreadId = Environment.CurrentManagedThreadId; + } + + [DebuggerHidden] + void IDisposable.Dispose() + { + int num = _003C_003E1__state; + if (num == -3 || num == 2) + { + try + { + } + finally + { + _003C_003Em__Finally1(); + } + } + _003CfirstParent_003E5__2 = null; + _003C_003E7__wrap2 = null; + _003C_003E1__state = -2; + } + + private bool MoveNext() + { + try + { + DependencyObject val2; + switch (_003C_003E1__state) + { + default: + return false; + case 0: + { + _003C_003E1__state = -1; + if (depObj == null) + { + return false; + } + _003CfirstParent_003E5__2 = LogicalTreeHelper.GetParent(depObj); + DependencyObject obj = _003CfirstParent_003E5__2; + T val = (T)(object)((obj is T) ? obj : null); + if (val != null) + { + _003C_003E2__current = val; + _003C_003E1__state = 1; + return true; + } + goto IL_0079; + } + case 1: + _003C_003E1__state = -1; + goto IL_0079; + case 2: + { + _003C_003E1__state = -3; + break; + } + IL_0079: + val2 = _003CfirstParent_003E5__2; + _003C_003E7__wrap2 = val2.FindParent<T>().GetEnumerator(); + _003C_003E1__state = -3; + break; + } + if (_003C_003E7__wrap2.MoveNext()) + { + T current = _003C_003E7__wrap2.Current; + _003C_003E2__current = current; + _003C_003E1__state = 2; + return true; + } + _003C_003Em__Finally1(); + _003C_003E7__wrap2 = null; + return false; + } + catch + { + //try-fault + ((IDisposable)this).Dispose(); + throw; + } + } + + bool IEnumerator.MoveNext() + { + //ILSpy generated this explicit interface implementation from .override directive in MoveNext + return this.MoveNext(); + } + + private void _003C_003Em__Finally1() + { + _003C_003E1__state = -1; + if (_003C_003E7__wrap2 != null) + { + _003C_003E7__wrap2.Dispose(); + } + } + + [DebuggerHidden] + void IEnumerator.Reset() + { + throw new NotSupportedException(); + } + + [DebuggerHidden] + IEnumerator<T> IEnumerable<T>.GetEnumerator() + { + _003CFindParent_003Ed__3<T> _003CFindParent_003Ed__; + if (_003C_003E1__state == -2 && _003C_003El__initialThreadId == Environment.CurrentManagedThreadId) + { + _003C_003E1__state = 0; + _003CFindParent_003Ed__ = this; + } + else + { + _003CFindParent_003Ed__ = new _003CFindParent_003Ed__3<T>(0); + } + _003CFindParent_003Ed__.depObj = _003C_003E3__depObj; + return _003CFindParent_003Ed__; + } + + [DebuggerHidden] + IEnumerator IEnumerable.GetEnumerator() + { + return ((IEnumerable<T>)this).GetEnumerator(); + } + } + + public static void ControlLostFocus(object sender, RoutedEventArgs e) + { + //IL_00a2: Unknown result type (might be due to invalid IL or missing references) + //IL_0675: Unknown result type (might be due to invalid IL or missing references) + //IL_0680: Expected O, but got Unknown + //IL_067b: Unknown result type (might be due to invalid IL or missing references) + //IL_0680: Unknown result type (might be due to invalid IL or missing references) + //IL_068a: Expected O, but got Unknown + Control val = null; + if (sender is CustomItemValidation) + { + val = ((DependencyObject)(object)(sender as CustomItemValidation)).FindChildren<Control>().FirstOrDefault((Func<Control, bool>)((Control currentControl) => currentControl is PasswordBox || currentControl is TextBox || currentControl is ToggleButton || currentControl is DatePicker || currentControl is ComboBox || currentControl is AutoCompleteBox || currentControl is CheckComboBox || currentControl is Button || currentControl is CustomPasswordBox)); + } + if (sender is CustomIsReadOnlyControl) + { + CustomIsReadOnlyControl customIsReadOnlyControl = sender as CustomIsReadOnlyControl; + val = ((!customIsReadOnlyControl.HasValidation) ? null : ((DependencyObject)(object)customIsReadOnlyControl).FindChildren<Control>().LastOrDefault((Func<Control, bool>)((Control currentControl) => currentControl is PasswordBox || currentControl is TextBox || currentControl is ToggleButton || currentControl is DatePicker || currentControl is ComboBox || currentControl is AutoCompleteBox || currentControl is CheckComboBox || currentControl is Button))); + } + if (val == null) + { + return; + } + ComboBox val2 = (ComboBox)(object)((val is ComboBox) ? val : null); + if ((val2 != null && val2.IsDropDownOpen) || (val is TextBox && ((TextBoxBase)(TextBox)val).IsReadOnly)) + { + return; + } + DependencyProperty dependencyProperty = GetDependencyProperty(val); + if (dependencyProperty == null) + { + return; + } + BindingExpression bindingExpression = ((FrameworkElement)val).GetBindingExpression(dependencyProperty); + if (bindingExpression == null) + { + return; + } + Validation.ClearInvalid((BindingExpressionBase)(object)bindingExpression); + List<string> list = bindingExpression.ParentBinding.Path.Path.Split(new char[1] { '.' }).ToList(); + Type type = bindingExpression.DataItem.GetType(); + if (!list.Any()) + { + return; + } + PropertyInfo property = type.GetProperty(list.First()); + if (property == null) + { + return; + } + dynamic value = property.GetValue(bindingExpression.DataItem, null); + List<KeyValuePair<string, string>> list2 = new List<KeyValuePair<string, string>>(); + if ((!ViewHelper.HasMethod(value, "ValidationEvent"))) + { + dynamic resolvedSource = bindingExpression.ResolvedSource; + if (resolvedSource is Control || ((!ViewHelper.HasMethod(resolvedSource, "ValidationEvent"))) || ((resolvedSource?.ValidationEvent == null) ? true : false)) + { + return; + } + if (resolvedSource.ValidationEvent is Func<List<KeyValuePair<string, string>>> func) + { + list2 = func(); + } + if (list2.Count == 0) + { + return; + } + } + if (list2.Count == 0) + { + if (value?.ValidationEvent == null) + { + return; + } + if (value.ValidationEvent is Func<List<KeyValuePair<string, string>>> func2) + { + list2 = func2(); + } + } + if (list2 == null || !list2.Any()) + { + return; + } + string text = ((list.Last() == "Id") ? list[list.Count - 2] : list.Last()); + string valueExact = ValidationHelper.GetValueExact(list2, text); + if (string.IsNullOrEmpty(valueExact)) + { + valueExact = ValidationHelper.GetValueExact(list2, text); + if (string.IsNullOrEmpty(valueExact)) + { + return; + } + } + ValidationError val3 = new ValidationError((ValidationRule)new ExceptionValidationRule(), (object)bindingExpression) + { + ErrorContent = valueExact + }; + Validation.MarkInvalid((BindingExpressionBase)(object)bindingExpression, val3); + } + + public static bool IsPropertyExist(dynamic settings, string name) + { + if (settings is ExpandoObject) + { + return ((IDictionary<string, object>)settings).ContainsKey(name); + } + return settings.GetType().GetProperty(name) != null; + } + + [IteratorStateMachine(typeof(_003CFindChildren_003Ed__2<>))] + public static IEnumerable<T> FindChildren<T>(this DependencyObject depObj) where T : DependencyObject + { + //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() + return new _003CFindChildren_003Ed__2<T>(-2) + { + _003C_003E3__depObj = depObj + }; + } + + [IteratorStateMachine(typeof(_003CFindParent_003Ed__3<>))] + public static IEnumerable<T> FindParent<T>(this DependencyObject depObj) where T : DependencyObject + { + //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() + return new _003CFindParent_003Ed__3<T>(-2) + { + _003C_003E3__depObj = depObj + }; + } + + public static T Window<T>() where T : Window + { + return ((IEnumerable)Application.Current.Windows).OfType<T>().FirstOrDefault(); + } + + public static void ValidateFields(this DependencyObject dependencyObject, List<KeyValuePair<string, string>> errorMessages, bool focusField = true) + { + if (errorMessages == null || !errorMessages.Any()) + { + dependencyObject.ClearInvalid(); + return; + } + Control val = null; + foreach (Control item in dependencyObject.FindChildren<Control>()) + { + Control val2 = item.SetInvalid(errorMessages); + if (val == null && val2 != null) + { + val = val2; + } + } + if (focusField && val != null) + { + ((UIElement)val).Focus(); + } + } + + public static Control SetInvalid(this Control currentControl, List<KeyValuePair<string, string>> errorMessages = null, string specificKey = null) + { + //IL_0320: Unknown result type (might be due to invalid IL or missing references) + //IL_032b: Expected O, but got Unknown + //IL_0326: Unknown result type (might be due to invalid IL or missing references) + //IL_032b: Unknown result type (might be due to invalid IL or missing references) + //IL_0335: Expected O, but got Unknown + DependencyProperty dependencyProperty = GetDependencyProperty(currentControl); + if (dependencyProperty == null) + { + return null; + } + BindingExpression bindingExpression = ((FrameworkElement)currentControl).GetBindingExpression(dependencyProperty); + if (errorMessages == null) + { + dynamic val = ((bindingExpression != null) ? bindingExpression.ResolvedSource : null); + if (val is Control) + { + return null; + } + if ((!ViewHelper.HasMethod(val, "ValidationEvent"))) + { + return null; + } + if (val?.ValidationEvent == null) + { + return null; + } + if (val.ValidationEvent is Func<List<KeyValuePair<string, string>>> func) + { + errorMessages = func(); + } + } + if (bindingExpression == null) + { + return null; + } + BindingExpressionBase bindingExpressionBase = BindingOperations.GetBindingExpressionBase((DependencyObject)(object)currentControl, dependencyProperty); + if (bindingExpressionBase == null) + { + return null; + } + Validation.ClearInvalid(bindingExpressionBase); + if (errorMessages == null || !errorMessages.Any()) + { + return null; + } + string[] array = bindingExpression.ParentBinding.Path.Path.Split(new char[1] { '.' }); + string text = specificKey ?? ((array.Last() == "Id") ? array[^2] : array.Last()); + string valueExact = ValidationHelper.GetValueExact(errorMessages, text); + if (string.IsNullOrEmpty(valueExact)) + { + valueExact = ValidationHelper.GetValueExact(errorMessages, text); + if (string.IsNullOrEmpty(valueExact)) + { + return null; + } + } + ValidationError val2 = new ValidationError((ValidationRule)new ExceptionValidationRule(), (object)bindingExpression) + { + ErrorContent = valueExact + }; + Validation.MarkInvalid(bindingExpressionBase, val2); + return currentControl; + } + + private static DependencyProperty GetDependencyProperty(Control currentControl) + { + DependencyProperty result = null; + if (currentControl is CheckComboBox) + { + result = Selector.SelectedValueProperty; + } + if (currentControl is DatePicker) + { + result = DatePicker.SelectedDateProperty; + } + if (currentControl is AutoCompleteBox) + { + result = AutoCompleteBox.SelectedItemProperty; + } + if (currentControl is TextBox) + { + result = TextBox.TextProperty; + } + if (currentControl is MaskedTextBox) + { + result = TextBox.TextProperty; + } + if (currentControl is ComboBox) + { + result = Selector.SelectedValueProperty; + } + if (currentControl is CurrencyTextBox) + { + result = CurrencyTextBox.NumberProperty; + } + if (currentControl is ToggleButton) + { + result = ToggleButton.IsCheckedProperty; + } + if (currentControl is CustomPasswordBox) + { + result = CustomPasswordBox.TextProperty; + } + return result; + } + + public static bool HasMethod(object objectToCheck, string methodName) + { + if (objectToCheck == null) + { + return false; + } + return objectToCheck.GetType().GetProperty(methodName) != null; + } + + public static bool IsValid(this DependencyObject obj) + { + if (!Validation.GetHasError(obj)) + { + return LogicalTreeHelper.GetChildren(obj).OfType<DependencyObject>().All(IsValid); + } + return false; + } + + public static void ClearInvalid(this DependencyObject dependencyObject) + { + foreach (Control item in dependencyObject.FindChildren<Control>()) + { + item.SetInvalid(); + } + } + + [IteratorStateMachine(typeof(_003CFindAncestor_003Ed__11<>))] + public static IEnumerable<T> FindAncestor<T>(this DependencyObject dependencyObject) where T : DependencyObject + { + //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() + return new _003CFindAncestor_003Ed__11<T>(-2) + { + _003C_003E3__dependencyObject = dependencyObject + }; + } + + private static bool Compare(Control currentControl) + { + DependencyProperty dependencyProperty = GetDependencyProperty(currentControl); + if (dependencyProperty == null) + { + return false; + } + BindingExpression bindingExpression = ((FrameworkElement)currentControl).GetBindingExpression(dependencyProperty); + dynamic val = ((bindingExpression != null) ? bindingExpression.ResolvedSource : null); + return val != null && (bool)val.HasChange(); + } + + public static bool IsWindowOpen<T>(string name = "") where T : Window + { + if (!string.IsNullOrEmpty(name)) + { + return ((IEnumerable)Application.Current.Windows).OfType<T>().Any((T w) => ((FrameworkElement)(object)w).Name.Equals(name)); + } + return ((IEnumerable)Application.Current.Windows).OfType<T>().Any(); + } + + public static void SetInvalid(Control control, string error, bool valid) + { + //IL_0017: Unknown result type (might be due to invalid IL or missing references) + //IL_0022: Expected O, but got Unknown + //IL_001d: Unknown result type (might be due to invalid IL or missing references) + //IL_0022: Unknown result type (might be due to invalid IL or missing references) + //IL_002a: Expected O, but got Unknown + DependencyProperty dependencyProperty = GetDependencyProperty(control); + if (dependencyProperty == null) + { + return; + } + BindingExpression bindingExpression = ((FrameworkElement)control).GetBindingExpression(dependencyProperty); + if (bindingExpression == null) + { + return; + } + ValidationError val = new ValidationError((ValidationRule)new ExceptionValidationRule(), (object)bindingExpression) + { + ErrorContent = error + }; + BindingExpressionBase bindingExpressionBase = BindingOperations.GetBindingExpressionBase((DependencyObject)(object)control, dependencyProperty); + if (bindingExpressionBase != null) + { + Validation.ClearInvalid(bindingExpressionBase); + if (!valid) + { + Validation.MarkInvalid(bindingExpressionBase, val); + } + } + } + + internal static void BindData<T>(this CheckComboBox comboBox, bool withSelect = true, bool enumDefault = true, string defaultValue = "", bool orderByLabel = false) + { + DefaultBinding<T>(comboBox, withSelect, enumDefault, defaultValue, string.Empty, orderByLabel); + } + + private static void DefaultBinding<T>(CheckComboBox comboBox, bool withSelect, bool enumDefault, string defaultValue = "", string defaultText = "", bool orderByLabel = false) + { + List<KeyValuePair<string, string>> source = (List<KeyValuePair<string, string>>)(((ItemsControl)comboBox).ItemsSource = BindingHelper.BindingData<T>(withSelect, enumDefault, defaultValue, defaultText, orderByLabel)); + ((Selector)comboBox).ValueMemberPath = "Key"; + ((ItemsControl)comboBox).DisplayMemberPath = "Value"; + ((Selector)comboBox).SelectedItem = source.First(); + } +} |