@@ -13,75 +13,44 @@ namespace KoAR.SaveEditor.Constructs
1313 /// </summary>
1414 public static class ValidatingPropertyBehavior
1515 {
16- /// <summary>
17- /// Defines the ValidatingProperty dependency property.
18- /// </summary>
1916 public static readonly DependencyProperty ValidatingPropertyProperty = DependencyProperty . RegisterAttached ( "ValidatingProperty" , typeof ( DependencyProperty ) , typeof ( ValidatingPropertyBehavior ) ,
2017 new ( ValidatingPropertyBehavior . ValidatingPropertyProperty_PropertyChanged ) ) ;
2118
22- /// <summary>
23- /// Gets the validating dependency property for a dependency object.
24- /// </summary>
25- /// <param name="dependencyObject">The dependency object.</param>
26- /// <returns>Dependency property.</returns>
2719 public static DependencyProperty ? GetValidatingProperty ( DependencyObject dependencyObject )
2820 {
2921 return ( DependencyProperty ? ) dependencyObject ? . GetValue ( ValidatingPropertyBehavior . ValidatingPropertyProperty ) ;
3022 }
3123
32- /// <summary>
33- /// Sets the validating dependency property for a dependency object.
34- /// </summary>
35- /// <param name="dependencyObject">The dependency object.</param>
36- /// <param name="property">The dependency property.</param>
3724 public static void SetValidatingProperty ( DependencyObject dependencyObject , DependencyProperty ? property )
3825 {
3926 dependencyObject ? . SetValue ( ValidatingPropertyBehavior . ValidatingPropertyProperty , property ) ;
4027 }
4128
42- /// <summary>
43- /// Called when the value of a validating property changes.
44- /// </summary>
45- /// <param name="sender">The source of the event.</param>
46- /// <param name="e">Event arguments.</param>
4729 private static void DependencyProperty_ValueChanged ( object sender , EventArgs e )
4830 {
4931 DependencyObject dependencyObject = ( DependencyObject ) sender ;
50- DependencyProperty ? property = ValidatingPropertyBehavior . GetValidatingProperty ( dependencyObject ) ;
51- if ( property != null )
32+ if ( ValidatingPropertyBehavior . GetValidatingProperty ( dependencyObject ) is DependencyProperty property )
5233 {
5334 dependencyObject . Validate ( property ) ;
5435 }
5536 }
5637
57- /// <summary>
58- /// Validate a value against a collection of validation rules.
59- /// </summary>
60- /// <param name="value">The value to validate.</param>
61- /// <param name="validationRules">The validation rules collection.</param>
62- /// <param name="bindingExpression">The binding expression.</param>
6338 private static void Validate ( object value , IEnumerable < ValidationRule > ? validationRules , BindingExpressionBase bindingExpression )
6439 {
6540 if ( validationRules != null )
6641 {
6742 foreach ( ValidationRule rule in validationRules )
6843 {
69- ValidationResult result = rule . Validate ( value , CultureInfo . InvariantCulture ) ;
70- if ( ! result . IsValid )
44+ if ( rule . Validate ( value , null ) is { IsValid : false , ErrorContent : object errorContent } )
7145 {
72- Validation . MarkInvalid ( bindingExpression , new ( rule , bindingExpression . ParentBindingBase , result . ErrorContent , null ) ) ;
46+ Validation . MarkInvalid ( bindingExpression , new ( rule , bindingExpression . ParentBindingBase , errorContent , null ) ) ;
7347 return ;
7448 }
7549 }
7650 }
7751 Validation . ClearInvalid ( bindingExpression ) ;
7852 }
7953
80- /// <summary>
81- /// Validate that a value of a dependency object/property combination does not violate any binding validation rules.
82- /// </summary>
83- /// <param name="dependencyObject">The dependency object.</param>
84- /// <param name="dependencyProperty">The dependency property.</param>
8554 private static void Validate ( this DependencyObject dependencyObject , DependencyProperty dependencyProperty )
8655 {
8756 BindingExpressionBase bindingExpression = BindingOperations . GetBindingExpressionBase ( dependencyObject , dependencyProperty ) ;
@@ -101,11 +70,6 @@ private static void Validate(this DependencyObject dependencyObject, DependencyP
10170 }
10271 }
10372
104- /// <summary>
105- /// Called when the value of the ValidatingProperty dependency property changes.
106- /// </summary>
107- /// <param name="d">The source of the event.</param>
108- /// <param name="e">Event arguments.</param>
10973 private static void ValidatingPropertyProperty_PropertyChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
11074 {
11175 if ( e . OldValue != null )
0 commit comments