File tree Expand file tree Collapse file tree 4 files changed +94
-0
lines changed
MaterialDesignThemes.UITests
MaterialDesignThemes.Wpf/Themes Expand file tree Collapse file tree 4 files changed +94
-0
lines changed Original file line number Diff line number Diff line change
1
+ <UserControl x : Class =" MaterialDesignThemes.UITests.Samples.PopupBox.PopupBoxWithTemplateSelector"
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
+ xmlns : local =" clr-namespace:MaterialDesignThemes.UITests.Samples.PopupBox" xmlns : materialDesign =" http://materialdesigninxaml.net/winfx/xaml/themes"
7
+ mc : Ignorable =" d"
8
+ d : DesignHeight =" 450" d : DesignWidth =" 800" >
9
+ <UserControl .Resources>
10
+ <DataTemplate x : Key =" OddTemplate" >
11
+ <Border Background =" Red" Width =" 10" Height =" 10" />
12
+ </DataTemplate >
13
+
14
+ <DataTemplate x : Key =" EvenTemplate" >
15
+ <Border Background =" Blue" Width =" 10" Height =" 10" />
16
+ </DataTemplate >
17
+
18
+ <local : ColorTemplateSelector x : Key =" ColorTemplateSelector"
19
+ OddTemplate =" {StaticResource OddTemplate}"
20
+ EvenTemplate =" {StaticResource EvenTemplate}" />
21
+ </UserControl .Resources>
22
+ <StackPanel >
23
+ <materialDesign : PopupBox
24
+
25
+ ToggleContentTemplateSelector =" {StaticResource ColorTemplateSelector}" x : Name =" MyPopupBox" />
26
+ <Button Content =" Toggle" Click =" Button_Click" />
27
+ </StackPanel >
28
+ </UserControl >
Original file line number Diff line number Diff line change
1
+
2
+ namespace MaterialDesignThemes . UITests . Samples . PopupBox ;
3
+
4
+ /// <summary>
5
+ /// Interaction logic for PopupBoxWithTemplateSelector.xaml
6
+ /// </summary>
7
+ public partial class PopupBoxWithTemplateSelector : UserControl
8
+ {
9
+ private int _counter ;
10
+ public PopupBoxWithTemplateSelector ( )
11
+ {
12
+ InitializeComponent ( ) ;
13
+ MyPopupBox . ToggleContent = _counter ;
14
+ }
15
+
16
+ private void Button_Click ( object sender , RoutedEventArgs e )
17
+ {
18
+ MyPopupBox . ToggleContent = ++ _counter ;
19
+ }
20
+ }
21
+
22
+ public class ColorTemplateSelector : DataTemplateSelector
23
+ {
24
+ public DataTemplate ? OddTemplate { get ; set ; }
25
+ public DataTemplate ? EvenTemplate { get ; set ; }
26
+
27
+ public override DataTemplate ? SelectTemplate ( object ? item , DependencyObject container )
28
+ {
29
+ if ( item is int intValue )
30
+ {
31
+ return intValue % 2 == 0 ? EvenTemplate : OddTemplate ;
32
+ }
33
+ return null ;
34
+ }
35
+ }
Original file line number Diff line number Diff line change 1
1
using System . ComponentModel ;
2
+ using System . Windows . Media ;
3
+ using MaterialDesignThemes . UITests . Samples . PopupBox ;
2
4
3
5
namespace MaterialDesignThemes . UITests . WPF . PopupBox ;
4
6
@@ -32,6 +34,34 @@ public async Task PopupBox_WithElevation_AppliesElevationToNestedCard(Elevation
32
34
// Assert
33
35
Assert . Equal ( elevation , await card . GetProperty < Elevation ? > ( ElevationAssist . ElevationProperty ) ) ;
34
36
37
+ recorder . Success ( ) ;
38
+ }
39
+
40
+ [ Fact ]
41
+ public async Task PopupBox_WithContentTemplateSelector_ChangesContent ( )
42
+ {
43
+ await using var recorder = new TestRecorder ( App ) ;
44
+
45
+ //Arrange
46
+ IVisualElement grid = ( await LoadUserControl < PopupBoxWithTemplateSelector > ( ) ) ;
47
+
48
+ IVisualElement < Button > button = await grid . GetElement < Button > ( ) ;
49
+ IVisualElement < Wpf . PopupBox > popupBox = await grid . GetElement < Wpf . PopupBox > ( ) ;
50
+
51
+
52
+ // Assert
53
+ var border = await popupBox . GetElement < Border > ( ) ;
54
+ Assert . Equal ( Colors . Blue , await border . GetBackgroundColor ( ) ) ;
55
+
56
+ await button . LeftClick ( ) ;
57
+
58
+ await Wait . For ( async ( ) =>
59
+ {
60
+ border = await popupBox . GetElement < Border > ( ) ;
61
+ Assert . Equal ( Colors . Red , await border . GetBackgroundColor ( ) ) ;
62
+ } ) ;
63
+
64
+
35
65
recorder . Success ( ) ;
36
66
}
37
67
}
Original file line number Diff line number Diff line change 106
106
VerticalContentAlignment =" {TemplateBinding VerticalContentAlignment}"
107
107
Content =" {TemplateBinding Content}"
108
108
ContentTemplate =" {TemplateBinding ContentTemplate}"
109
+ ContentTemplateSelector =" {TemplateBinding ContentTemplateSelector}"
109
110
Focusable =" False"
110
111
SnapsToDevicePixels =" {TemplateBinding SnapsToDevicePixels}" />
111
112
</ControlTemplate >
You can’t perform that action at this time.
0 commit comments