File tree Expand file tree Collapse file tree 4 files changed +95
-2
lines changed
MaterialDesignThemes.UITests
MaterialDesignThemes.Wpf/Themes Expand file tree Collapse file tree 4 files changed +95
-2
lines changed Original file line number Diff line number Diff line change
1
+ <UserControl x : Class =" MaterialDesignThemes.UITests.Samples.Validation.ValidationUpdates"
2
+ xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3
+ xmlns : x =" http://schemas.microsoft.com/winfx/2006/xaml"
4
+ xmlns : mc =" http://schemas.openxmlformats.org/markup-compatibility/2006"
5
+ xmlns : d =" http://schemas.microsoft.com/expression/blend/2008"
6
+ mc : Ignorable =" d"
7
+ d : DesignHeight =" 450" d : DesignWidth =" 800" >
8
+ <Grid >
9
+ <Grid .RowDefinitions>
10
+ <RowDefinition />
11
+ <RowDefinition />
12
+ </Grid .RowDefinitions>
13
+
14
+ <TextBox Text =" {Binding Text, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True}"
15
+ VerticalAlignment =" Center" />
16
+
17
+ <Button Command =" {Binding CauseErrorsCommand}" Content =" Validate" Grid.Row=" 1" VerticalAlignment =" Center" />
18
+ </Grid >
19
+ </UserControl >
Original file line number Diff line number Diff line change
1
+ using System . Collections ;
2
+ using System . ComponentModel ;
3
+ using System . ComponentModel . DataAnnotations ;
4
+ using CommunityToolkit . Mvvm . ComponentModel ;
5
+ using CommunityToolkit . Mvvm . Input ;
6
+
7
+ namespace MaterialDesignThemes . UITests . Samples . Validation ;
8
+
9
+ /// <summary>
10
+ /// Interaction logic for ValidationUpdates.xaml
11
+ /// </summary>
12
+ public partial class ValidationUpdates
13
+ {
14
+ public ValidationUpdates ( )
15
+ {
16
+ DataContext = new ValidationUpdatesViewModel ( ) ;
17
+ InitializeComponent ( ) ;
18
+ }
19
+ }
20
+
21
+ public partial class ValidationUpdatesViewModel : ObservableObject , INotifyDataErrorInfo
22
+ {
23
+ [ ObservableProperty ]
24
+ private string ? _text ;
25
+
26
+ private string ? Error { get ; set ; }
27
+
28
+ public bool HasErrors => Error != null ;
29
+
30
+ public event EventHandler < DataErrorsChangedEventArgs > ? ErrorsChanged ;
31
+
32
+ public IEnumerable GetErrors ( string ? propertyName )
33
+ {
34
+ if ( propertyName == nameof ( Text ) )
35
+ {
36
+ if ( Error != null )
37
+ {
38
+ return new [ ] { Error } ;
39
+ }
40
+ }
41
+ return Enumerable . Empty < string > ( ) ;
42
+ }
43
+
44
+ [ RelayCommand ]
45
+ private async Task CauseErrors ( )
46
+ {
47
+ Error = "Some error" ;
48
+ ErrorsChanged ? . Invoke ( this , new DataErrorsChangedEventArgs ( nameof ( Text ) ) ) ;
49
+ await Task . Delay ( 100 ) ;
50
+ Error += " + more" ;
51
+ ErrorsChanged ? . Invoke ( this , new DataErrorsChangedEventArgs ( nameof ( Text ) ) ) ;
52
+ }
53
+ }
Original file line number Diff line number Diff line change 1
1
using System . ComponentModel ;
2
2
using System . Globalization ;
3
3
using System . Windows . Media ;
4
+ using MaterialDesignThemes . UITests . Samples . Validation ;
4
5
5
6
namespace MaterialDesignThemes . UITests . WPF . TextBoxes ;
6
7
@@ -590,6 +591,26 @@ public async Task TextBox_MultiLineAndFixedHeight_RespectsVerticalContentAlignme
590
591
591
592
recorder . Success ( ) ;
592
593
}
594
+
595
+ [ Fact ]
596
+ [ Description ( "Issue 3176" ) ]
597
+ public async Task ValidationErrorTemplate_WithChangingErrors_UpdatesValidation ( )
598
+ {
599
+ await using var recorder = new TestRecorder ( App ) ;
600
+
601
+ IVisualElement userControl = await LoadUserControl < ValidationUpdates > ( ) ;
602
+ var textBox = await userControl . GetElement < TextBox > ( ) ;
603
+ var button = await userControl . GetElement < Button > ( ) ;
604
+ await button . LeftClick ( ) ;
605
+
606
+ await Wait . For ( async ( ) =>
607
+ {
608
+ var errorViewer = await textBox . GetElement ( "DefaultErrorViewer" ) ;
609
+ var textBlock = await errorViewer . GetElement < TextBlock > ( ) ;
610
+
611
+ Assert . Equal ( "Some error + more" , await textBlock . GetText ( ) ) ;
612
+ } ) ;
613
+ }
593
614
}
594
615
595
616
public class NotEmptyValidationRule : ValidationRule
Original file line number Diff line number Diff line change 32
32
HorizontalAlignment =" {Binding ElementName=Placeholder, Path=AdornedElement.(wpf:ValidationAssist.HorizontalAlignment)}"
33
33
FontSize =" {Binding ElementName=Placeholder, Path=AdornedElement.(wpf:ValidationAssist.FontSize)}"
34
34
Foreground =" {DynamicResource MaterialDesignValidationErrorBrush}"
35
- Text =" {Binding CurrentItem. ErrorContent, Mode=OneTime}"
35
+ Text =" {Binding / ErrorContent, Mode=OneTime}"
36
36
TextWrapping =" Wrap"
37
37
UseLayoutRounding =" false" />
38
38
</Border >
46
46
HorizontalAlignment =" {Binding ElementName=Placeholder, Path=AdornedElement.(wpf:ValidationAssist.HorizontalAlignment)}"
47
47
FontSize =" {Binding ElementName=Placeholder, Path=AdornedElement.(wpf:ValidationAssist.FontSize)}"
48
48
Foreground =" {DynamicResource MaterialDesignValidationErrorBrush}"
49
- Text =" {Binding CurrentItem. ErrorContent, Mode=OneTime}"
49
+ Text =" {Binding / ErrorContent, Mode=OneTime}"
50
50
TextWrapping =" Wrap"
51
51
UseLayoutRounding =" false" />
52
52
</Border >
You can’t perform that action at this time.
0 commit comments