Skip to content

Commit fb79306

Browse files
Added CornerRadius to DialogHost (#2803)
* Added CornerRadius to DialogHost * Fixed failing UI test * Rollback UI test fix, and bind Visibility to retain original behavior * Added test for embedded style
1 parent 5c169da commit fb79306

File tree

3 files changed

+115
-31
lines changed

3 files changed

+115
-31
lines changed

MaterialDesignThemes.UITests/WPF/DialogHosts/DialogHostTests.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,5 +255,73 @@ await textBlock2.GetEffectiveBackground(),
255255

256256
recorder.Success();
257257
}
258+
259+
[Fact]
260+
[Description("Issue 2772")]
261+
public async Task CornerRadius_AppliedToContentCoverBorder_WhenSetOnDialogHost()
262+
{
263+
await using var recorder = new TestRecorder(App);
264+
265+
IVisualElement grid = await LoadXaml<Grid>(@"
266+
<Grid>
267+
<materialDesign:DialogHost x:Name=""DialogHost"" CornerRadius=""1,2,3,4"">
268+
<materialDesign:DialogHost.DialogContent>
269+
<TextBlock Text=""Some Text"" />
270+
</materialDesign:DialogHost.DialogContent>
271+
<Button Content=""Show Dialog"" x:Name=""ShowButton"" Command=""{x:Static materialDesign:DialogHost.OpenDialogCommand}"" />
272+
</materialDesign:DialogHost>
273+
</Grid>");
274+
275+
var showButton = await grid.GetElement<Button>("ShowButton");
276+
var dialogHost = await grid.GetElement<DialogHost>("DialogHost");
277+
278+
await showButton.LeftClick();
279+
280+
await Wait.For(async () =>
281+
{
282+
var contentCoverBorder = await dialogHost.GetElement<Border>("ContentCoverBorder");
283+
284+
Assert.Equal(1, (await contentCoverBorder.GetCornerRadius()).TopLeft);
285+
Assert.Equal(2, (await contentCoverBorder.GetCornerRadius()).TopRight);
286+
Assert.Equal(3, (await contentCoverBorder.GetCornerRadius()).BottomRight);
287+
Assert.Equal(4, (await contentCoverBorder.GetCornerRadius()).BottomLeft);
288+
});
289+
290+
recorder.Success();
291+
}
292+
293+
[Fact]
294+
[Description("Issue 2772")]
295+
public async Task CornerRadius_AppliedToContentCoverBorder_WhenSetOnEmbeddedDialogHost()
296+
{
297+
await using var recorder = new TestRecorder(App);
298+
299+
IVisualElement grid = await LoadXaml<Grid>(@"
300+
<Grid>
301+
<materialDesign:DialogHost x:Name=""DialogHost"" Style=""{StaticResource MaterialDesignEmbeddedDialogHost}"" CornerRadius=""1,2,3,4"">
302+
<materialDesign:DialogHost.DialogContent>
303+
<TextBlock Text=""Some Text"" />
304+
</materialDesign:DialogHost.DialogContent>
305+
<Button Content=""Show Dialog"" x:Name=""ShowButton"" Command=""{x:Static materialDesign:DialogHost.OpenDialogCommand}"" />
306+
</materialDesign:DialogHost>
307+
</Grid>");
308+
309+
var showButton = await grid.GetElement<Button>("ShowButton");
310+
var dialogHost = await grid.GetElement<DialogHost>("DialogHost");
311+
312+
await showButton.LeftClick();
313+
314+
await Wait.For(async () =>
315+
{
316+
var contentCoverBorder = await dialogHost.GetElement<Border>("ContentCoverBorder");
317+
318+
Assert.Equal(1, (await contentCoverBorder.GetCornerRadius()).TopLeft);
319+
Assert.Equal(2, (await contentCoverBorder.GetCornerRadius()).TopRight);
320+
Assert.Equal(3, (await contentCoverBorder.GetCornerRadius()).BottomRight);
321+
Assert.Equal(4, (await contentCoverBorder.GetCornerRadius()).BottomLeft);
322+
});
323+
324+
recorder.Success();
325+
}
258326
}
259327
}

MaterialDesignThemes.Wpf/DialogHost.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,15 @@ public PlacementMode Placement
405405
set => SetValue(PlacementProperty, value);
406406
}
407407

408+
public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register(
409+
nameof(CornerRadius), typeof(CornerRadius), typeof(DialogHost), new PropertyMetadata(default(CornerRadius)));
410+
411+
public CornerRadius CornerRadius
412+
{
413+
get { return (CornerRadius) GetValue(CornerRadiusProperty); }
414+
set { SetValue(CornerRadiusProperty, value); }
415+
}
416+
408417
public static readonly DependencyProperty DialogContentProperty = DependencyProperty.Register(
409418
nameof(DialogContent), typeof(object), typeof(DialogHost), new PropertyMetadata(default(object)));
410419

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DialogHost.xaml

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="PART_Popup" Storyboard.TargetProperty="IsOpen">
3131
<DiscreteBooleanKeyFrame Value="True" KeyTime="0" />
3232
</BooleanAnimationUsingKeyFrames>
33-
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="PART_ContentCoverGrid" Storyboard.TargetProperty="Opacity">
33+
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="ContentCoverBorder" Storyboard.TargetProperty="Opacity">
3434
<EasingDoubleKeyFrame Value="0" KeyTime="0" />
3535
<EasingDoubleKeyFrame Value="0.56" KeyTime="0:0:0.3">
3636
<EasingDoubleKeyFrame.EasingFunction>
@@ -69,7 +69,7 @@
6969
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="PART_Popup" Storyboard.TargetProperty="IsOpen">
7070
<DiscreteBooleanKeyFrame Value="False" KeyTime="0:0:0.3" />
7171
</BooleanAnimationUsingKeyFrames>
72-
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="PART_ContentCoverGrid" Storyboard.TargetProperty="Opacity">
72+
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="ContentCoverBorder" Storyboard.TargetProperty="Opacity">
7373
<EasingDoubleKeyFrame Value="0.56" KeyTime="0" />
7474
<EasingDoubleKeyFrame Value="0" KeyTime="0:0:0.3">
7575
<EasingDoubleKeyFrame.EasingFunction>
@@ -113,7 +113,7 @@
113113
Duration="0">
114114
<DiscreteBooleanKeyFrame Value="True" KeyTime="0" />
115115
</BooleanAnimationUsingKeyFrames>
116-
<DoubleAnimation Storyboard.TargetName="PART_ContentCoverGrid" Storyboard.TargetProperty="Opacity"
116+
<DoubleAnimation Storyboard.TargetName="ContentCoverBorder" Storyboard.TargetProperty="Opacity"
117117
Duration="0"
118118
To=".56" />
119119
<DoubleAnimation Storyboard.TargetName="PART_PopupContentElement" Storyboard.TargetProperty="Opacity"
@@ -132,7 +132,7 @@
132132
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="PART_Popup" Storyboard.TargetProperty="IsOpen">
133133
<DiscreteBooleanKeyFrame Value="False" KeyTime="0" />
134134
</BooleanAnimationUsingKeyFrames>
135-
<DoubleAnimation Storyboard.TargetName="PART_ContentCoverGrid" Storyboard.TargetProperty="Opacity"
135+
<DoubleAnimation Storyboard.TargetName="ContentCoverBorder" Storyboard.TargetProperty="Opacity"
136136
To="0" Duration="0"/>
137137
</Storyboard>
138138
</VisualState>
@@ -193,17 +193,21 @@
193193
<ContentPresenter x:Name="ContentPresenter" Opacity="1" Content="{TemplateBinding ContentControl.Content}"
194194
ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" />
195195
</AdornerDecorator>
196-
<Grid x:Name="PART_ContentCoverGrid" Background="{Binding OverlayBackground, RelativeSource={RelativeSource TemplatedParent}}"
197-
Opacity="0" IsHitTestVisible="False" Focusable="False">
198-
<Grid.Style>
199-
<Style TargetType="Grid">
200-
<Style.Triggers>
201-
<Trigger Property="Opacity" Value="0">
202-
<Setter Property="Visibility" Value="Hidden" />
203-
</Trigger>
204-
</Style.Triggers>
205-
</Style>
206-
</Grid.Style>
196+
<Grid x:Name="PART_ContentCoverGrid" Background="Transparent" IsHitTestVisible="False" Focusable="False" Visibility="{Binding ElementName=ContentCoverBorder, Path=Visibility}">
197+
<Grid.OpacityMask>
198+
<VisualBrush Visual="{Binding ElementName=ContentCoverBorder}" />
199+
</Grid.OpacityMask>
200+
<Border x:Name="ContentCoverBorder" Opacity="0" CornerRadius="{TemplateBinding CornerRadius}" Background="{Binding OverlayBackground, RelativeSource={RelativeSource TemplatedParent}}" IsHitTestVisible="False">
201+
<Border.Style>
202+
<Style TargetType="Border">
203+
<Style.Triggers>
204+
<Trigger Property="Opacity" Value="0">
205+
<Setter Property="Visibility" Value="Hidden" />
206+
</Trigger>
207+
</Style.Triggers>
208+
</Style>
209+
</Border.Style>
210+
</Border>
207211
</Grid>
208212
</Grid>
209213
<ControlTemplate.Triggers>
@@ -234,7 +238,7 @@
234238
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_Popup" Storyboard.TargetProperty="Visibility">
235239
<DiscreteObjectKeyFrame Value="{x:Static Visibility.Visible}" KeyTime="0" />
236240
</ObjectAnimationUsingKeyFrames>
237-
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="PART_ContentCoverGrid" Storyboard.TargetProperty="Opacity">
241+
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="ContentCoverBorder" Storyboard.TargetProperty="Opacity">
238242
<EasingDoubleKeyFrame Value="0" KeyTime="0" />
239243
<EasingDoubleKeyFrame Value="0.56" KeyTime="0:0:0.3">
240244
<EasingDoubleKeyFrame.EasingFunction>
@@ -273,7 +277,7 @@
273277
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_Popup" Storyboard.TargetProperty="Visibility">
274278
<DiscreteObjectKeyFrame Value="{x:Static Visibility.Collapsed}" KeyTime="0:0:0.3" />
275279
</ObjectAnimationUsingKeyFrames>
276-
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="PART_ContentCoverGrid" Storyboard.TargetProperty="Opacity">
280+
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="ContentCoverBorder" Storyboard.TargetProperty="Opacity">
277281
<EasingDoubleKeyFrame Value="0.56" KeyTime="0" />
278282
<EasingDoubleKeyFrame Value="0" KeyTime="0:0:0.3">
279283
<EasingDoubleKeyFrame.EasingFunction>
@@ -317,7 +321,7 @@
317321
Duration="0">
318322
<DiscreteObjectKeyFrame Value="{x:Static Visibility.Visible}" KeyTime="0" />
319323
</ObjectAnimationUsingKeyFrames>
320-
<DoubleAnimation Storyboard.TargetName="PART_ContentCoverGrid" Storyboard.TargetProperty="Opacity"
324+
<DoubleAnimation Storyboard.TargetName="ContentCoverBorder" Storyboard.TargetProperty="Opacity"
321325
Duration="0"
322326
To=".56" />
323327
<DoubleAnimation Storyboard.TargetName="PART_PopupContentElement" Storyboard.TargetProperty="Opacity"
@@ -337,7 +341,7 @@
337341
Duration="0">
338342
<DiscreteObjectKeyFrame Value="{x:Static Visibility.Collapsed}" KeyTime="0" />
339343
</ObjectAnimationUsingKeyFrames>
340-
<DoubleAnimation Storyboard.TargetName="PART_ContentCoverGrid" Storyboard.TargetProperty="Opacity"
344+
<DoubleAnimation Storyboard.TargetName="ContentCoverBorder" Storyboard.TargetProperty="Opacity"
341345
To="0" />
342346
</Storyboard>
343347
</VisualState>
@@ -347,18 +351,21 @@
347351
x:Name="ContentPresenter" Opacity="1"
348352
Content="{TemplateBinding ContentControl.Content}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" />
349353

350-
<Grid x:Name="PART_ContentCoverGrid"
351-
Background="{Binding OverlayBackground, RelativeSource={RelativeSource TemplatedParent}}"
352-
Opacity="0" IsHitTestVisible="False" Focusable="False">
353-
<Grid.Style>
354-
<Style TargetType="Grid">
355-
<Style.Triggers>
356-
<Trigger Property="Opacity" Value="0">
357-
<Setter Property="Visibility" Value="Hidden" />
358-
</Trigger>
359-
</Style.Triggers>
360-
</Style>
361-
</Grid.Style>
354+
<Grid x:Name="PART_ContentCoverGrid" Background="Transparent" IsHitTestVisible="False" Focusable="False" Visibility="{Binding ElementName=ContentCoverBorder, Path=Visibility}">
355+
<Grid.OpacityMask>
356+
<VisualBrush Visual="{Binding ElementName=ContentCoverBorder}" />
357+
</Grid.OpacityMask>
358+
<Border x:Name="ContentCoverBorder" Opacity="0" CornerRadius="{TemplateBinding CornerRadius}" Background="{Binding OverlayBackground, RelativeSource={RelativeSource TemplatedParent}}" IsHitTestVisible="False">
359+
<Border.Style>
360+
<Style TargetType="Border">
361+
<Style.Triggers>
362+
<Trigger Property="Opacity" Value="0">
363+
<Setter Property="Visibility" Value="Hidden" />
364+
</Trigger>
365+
</Style.Triggers>
366+
</Style>
367+
</Border.Style>
368+
</Border>
362369
</Grid>
363370

364371
<Grid x:Name="PART_Popup" wpf:ThemeAssist.Theme="{TemplateBinding DialogTheme}"

0 commit comments

Comments
 (0)