Skip to content

Commit 505ea07

Browse files
authored
Add support for various properties to PopupBox (#4011)
* fix(popupbox): add support for Background, BorderBrush, BorderThickness and ButtonAssist.CornerRadius and hover-effect to PopupBox * test(popupbox): get border by unique name because the PopupBox now contains a nested border in it's template, the test was broken because it was getting the border in the template instead of the call-site defined content, which is wrong. getting the border by x:Name disambiguates them
1 parent 8fa961f commit 505ea07

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.PopupBox.xaml

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,40 @@
9595
<Setter Property="Template">
9696
<Setter.Value>
9797
<ControlTemplate TargetType="ToggleButton">
98-
<wpf:Ripple Padding="{TemplateBinding Padding}"
99-
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
100-
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
101-
Content="{TemplateBinding Content}"
102-
ContentTemplate="{TemplateBinding ContentTemplate}"
103-
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
104-
Focusable="False"
105-
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
98+
<Grid>
99+
<Border x:Name="border"
100+
Background="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=wpf:PopupBox}, Path=Background}"
101+
BorderBrush="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=wpf:PopupBox}, Path=BorderBrush}"
102+
BorderThickness="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=wpf:PopupBox}, Path=BorderThickness}"
103+
CornerRadius="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=wpf:PopupBox}, Path=(wpf:ButtonAssist.CornerRadius)}" />
104+
105+
<wpf:Ripple Padding="{TemplateBinding Padding}"
106+
ClipToBounds="True"
107+
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
108+
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
109+
Content="{TemplateBinding Content}"
110+
ContentTemplate="{TemplateBinding ContentTemplate}"
111+
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
112+
Focusable="False"
113+
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
114+
<wpf:Ripple.Clip>
115+
<MultiBinding Converter="{x:Static converters:BorderClipConverter.Instance}">
116+
<Binding ElementName="border" Path="ActualWidth" />
117+
<Binding ElementName="border" Path="ActualHeight" />
118+
<Binding ElementName="border" Path="CornerRadius" />
119+
<Binding ElementName="border" Path="BorderThickness" />
120+
</MultiBinding>
121+
</wpf:Ripple.Clip>
122+
</wpf:Ripple>
123+
</Grid>
124+
<ControlTemplate.Triggers>
125+
<Trigger Property="IsMouseOver" Value="true">
126+
<Setter TargetName="border" Property="Background" Value="{Binding Foreground, RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={x:Static converters:BrushOpacityConverter.Instance}, ConverterParameter=0.16}" />
127+
</Trigger>
128+
<Trigger Property="IsEnabled" Value="false">
129+
<Setter Property="Opacity" Value="0.38" />
130+
</Trigger>
131+
</ControlTemplate.Triggers>
106132
</ControlTemplate>
107133
</Setter.Value>
108134
</Setter>

tests/MaterialDesignThemes.UITests/Samples/PopupBox/PopupBoxWithTemplateSelector.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
d:DesignHeight="450" d:DesignWidth="800">
99
<UserControl.Resources>
1010
<DataTemplate x:Key="OddTemplate">
11-
<Border Background="Red" Width="10" Height="10" />
11+
<Border x:Name="ContentBorder" Background="Red" Width="10" Height="10" />
1212
</DataTemplate>
1313

1414
<DataTemplate x:Key="EvenTemplate">
15-
<Border Background="Blue" Width="10" Height="10" />
15+
<Border x:Name="ContentBorder" Background="Blue" Width="10" Height="10" />
1616
</DataTemplate>
1717

1818
<local:ColorTemplateSelector x:Key="ColorTemplateSelector"

tests/MaterialDesignThemes.UITests/WPF/PopupBoxes/PopupBoxTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ public async Task PopupBox_WithContentTemplateSelector_ChangesContent()
4646

4747

4848
// Assert
49-
var border = await popupBox.GetElement<Border>();
49+
var border = await popupBox.GetElement<Border>("ContentBorder");
5050
await Assert.That(await border.GetBackgroundColor()).IsEqualTo(Colors.Blue);
5151

5252
await button.LeftClick();
5353

5454
await Wait.For(async () =>
5555
{
56-
border = await popupBox.GetElement<Border>();
56+
border = await popupBox.GetElement<Border>("ContentBorder");
5757
await Assert.That(await border.GetBackgroundColor()).IsEqualTo(Colors.Red);
5858
});
5959

0 commit comments

Comments
 (0)