Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DialogHost.DialogCardStyle DP to allow control from calling code #3459

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions MaterialDesignThemes.UITests/WPF/DialogHosts/DialogHostTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -480,4 +480,56 @@ public async Task DialogHost_ChangesSelectedRailItem_DoesNotPerformRailChangeWhe

recorder.Success();
}

[Theory]
[InlineData("MaterialDesignElevatedCard")]
[InlineData("MaterialDesignOutlinedCard")]
[Description("Issue 3430")]
public async Task DialogHost_DefaultStyleWithDialogCardStyleApplied_PassesStyleToNestedCard(string dialogCardStyle)
{
await using var recorder = new TestRecorder(App);

IVisualElement grid = await LoadXaml<Grid>($$"""
<Grid>
<materialDesign:DialogHost x:Name="DialogHost" IsOpen="True" DialogCardStyle="{StaticResource {{dialogCardStyle}}}">
<materialDesign:DialogHost.DialogContent>
<TextBlock Text="Some Text" Margin="100" />
</materialDesign:DialogHost.DialogContent>
</materialDesign:DialogHost>
</Grid>
""");

IVisualElement<DialogHost> dialogHost = await grid.GetElement<DialogHost>("DialogHost");
IVisualElement<Card> nestedCard = await dialogHost.GetElement<Card>("PART_PopupContentElement");

// TODO: Assert the style on the nested card matches what is set in DialogHost.DialogCardStyle
Copy link
Contributor Author

@nicolaihenriksen nicolaihenriksen Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Keboo this is where I hit a road block. Any help would be appreciated 🙏


recorder.Success();
}

[Theory]
[InlineData("MaterialDesignElevatedCard")]
[InlineData("MaterialDesignOutlinedCard")]
[Description("Issue 3430")]
public async Task DialogHost_EmbeddedStyleWithDialogCardStyleApplied_PassesStyleToNestedCard(string dialogCardStyle)
{
await using var recorder = new TestRecorder(App);

IVisualElement grid = await LoadXaml<Grid>($$"""
<Grid>
<materialDesign:DialogHost x:Name="DialogHost" Style="{StaticResource MaterialDesignEmbeddedDialogHost}" IsOpen="True" DialogCardStyle="{StaticResource {{dialogCardStyle}}}">
<materialDesign:DialogHost.DialogContent>
<TextBlock Text="Some Text" Margin="100" />
</materialDesign:DialogHost.DialogContent>
</materialDesign:DialogHost>
</Grid>
""");

IVisualElement<DialogHost> dialogHost = await grid.GetElement<DialogHost>("DialogHost");
IVisualElement<Card> nestedCard = await dialogHost.GetElement<Card>("PART_PopupContentElement");

// TODO: Assert the style on the nested card matches what is set in DialogHost.DialogCardStyle

recorder.Success();
}
}
23 changes: 16 additions & 7 deletions MaterialDesignThemes.Wpf/DialogHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ public string? DialogContentStringFormat
}

public static readonly DependencyProperty DialogMarginProperty = DependencyProperty.Register(
"DialogMargin", typeof(Thickness), typeof(DialogHost), new PropertyMetadata(default(Thickness)));
nameof(DialogMargin), typeof(Thickness), typeof(DialogHost), new PropertyMetadata(default(Thickness)));

public Thickness DialogMargin
{
Expand All @@ -494,6 +494,15 @@ public Thickness DialogMargin
public static readonly DependencyProperty OpenDialogCommandDataContextSourceProperty = DependencyProperty.Register(
nameof(OpenDialogCommandDataContextSource), typeof(DialogHostOpenDialogCommandDataContextSource), typeof(DialogHost), new PropertyMetadata(default(DialogHostOpenDialogCommandDataContextSource)));

public static readonly DependencyProperty DialogCardStyleProperty = DependencyProperty.Register(
nameof(DialogCardStyle), typeof(Style), typeof(DialogHost), new PropertyMetadata(default(Style)));

public Style DialogCardStyle
{
get => (Style) GetValue(DialogCardStyleProperty);
set => SetValue(DialogCardStyleProperty, value);
}

/// <summary>
/// Defines how a data context is sourced for a dialog if a <see cref="FrameworkElement"/>
/// is passed as the command parameter when using <see cref="DialogHost.OpenDialogCommand"/>.
Expand All @@ -505,7 +514,7 @@ public DialogHostOpenDialogCommandDataContextSource OpenDialogCommandDataContext
}

public static readonly DependencyProperty CloseOnClickAwayProperty = DependencyProperty.Register(
"CloseOnClickAway", typeof(bool), typeof(DialogHost), new PropertyMetadata(default(bool)));
nameof(CloseOnClickAway), typeof(bool), typeof(DialogHost), new PropertyMetadata(default(bool)));

/// <summary>
/// Indicates whether the dialog will close if the user clicks off the dialog, on the obscured background.
Expand All @@ -517,7 +526,7 @@ public bool CloseOnClickAway
}

public static readonly DependencyProperty CloseOnClickAwayParameterProperty = DependencyProperty.Register(
"CloseOnClickAwayParameter", typeof(object), typeof(DialogHost), new PropertyMetadata(default(object)));
nameof(CloseOnClickAwayParameter), typeof(object), typeof(DialogHost), new PropertyMetadata(default(object)));

/// <summary>
/// Parameter to provide to close handlers if an close due to click away is instigated.
Expand All @@ -529,7 +538,7 @@ public object? CloseOnClickAwayParameter
}

public static readonly DependencyProperty SnackbarMessageQueueProperty = DependencyProperty.Register(
"SnackbarMessageQueue", typeof(SnackbarMessageQueue), typeof(DialogHost), new PropertyMetadata(default(SnackbarMessageQueue), SnackbarMessageQueuePropertyChangedCallback));
nameof(SnackbarMessageQueue), typeof(SnackbarMessageQueue), typeof(DialogHost), new PropertyMetadata(default(SnackbarMessageQueue), SnackbarMessageQueuePropertyChangedCallback));

private static void SnackbarMessageQueuePropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
Expand Down Expand Up @@ -642,7 +651,7 @@ public bool IsRestoreFocusDisabled

public static readonly RoutedEvent DialogOpenedEvent =
EventManager.RegisterRoutedEvent(
"DialogOpened",
nameof(DialogOpened),
RoutingStrategy.Bubble,
typeof(DialogOpenedEventHandler),
typeof(DialogHost));
Expand Down Expand Up @@ -689,7 +698,7 @@ protected void OnDialogOpened(DialogOpenedEventArgs eventArgs)

public static readonly RoutedEvent DialogClosingEvent =
EventManager.RegisterRoutedEvent(
"DialogClosing",
nameof(DialogClosing),
RoutingStrategy.Bubble,
typeof(DialogClosingEventHandler),
typeof(DialogHost));
Expand Down Expand Up @@ -732,7 +741,7 @@ protected void OnDialogClosing(DialogClosingEventArgs eventArgs)

public static readonly RoutedEvent DialogClosedEvent =
EventManager.RegisterRoutedEvent(
"DialogClosed",
nameof(DialogClosed),
RoutingStrategy.Bubble,
typeof(DialogClosedEventHandler),
typeof(DialogHost));
Expand Down
30 changes: 10 additions & 20 deletions MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DialogHost.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
<wpf:Card x:Name="PART_PopupContentElement"
Margin="{TemplateBinding DialogMargin}"
wpf:ElevationAssist.Elevation="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ElevationAssist.Elevation)}"
Background="{Binding Tag, RelativeSource={RelativeSource Self}}"
Content="{TemplateBinding DialogContent}"
ContentStringFormat="{TemplateBinding DialogContentStringFormat}"
ContentTemplate="{TemplateBinding DialogContentTemplate}"
Expand All @@ -171,19 +172,10 @@
IsTabStop="False"
Opacity="0"
RenderTransformOrigin=".5,.5"
Style="{TemplateBinding DialogCardStyle}"
Tag="{TemplateBinding DialogBackground}"
TextElement.Foreground="{DynamicResource MaterialDesign.Brush.Foreground}"
UniformCornerRadius="{TemplateBinding DialogContentUniformCornerRadius}">
<wpf:Card.Style>
<Style TargetType="wpf:Card" BasedOn="{StaticResource {x:Type wpf:Card}}">
<Setter Property="Background" Value="{Binding Tag, RelativeSource={RelativeSource Self}}" />
<Style.Triggers>
<Trigger Property="Tag" Value="{x:Null}">
<Setter Property="Background" Value="{DynamicResource MaterialDesign.Brush.Background}" />
</Trigger>
</Style.Triggers>
</Style>
</wpf:Card.Style>
<wpf:Card.RenderTransform>
<TransformGroup>
<ScaleTransform x:Name="CardScaleTransform" ScaleX="0" ScaleY="0" />
Expand Down Expand Up @@ -228,6 +220,9 @@
<Trigger Property="IsOpen" Value="True">
<Setter TargetName="PART_ContentCoverGrid" Property="IsHitTestVisible" Value="True" />
</Trigger>
<Trigger SourceName="PART_PopupContentElement" Property="Tag" Value="{x:Null}">
<Setter TargetName="PART_PopupContentElement" Property="Background" Value="{DynamicResource MaterialDesign.Brush.Background}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
Expand Down Expand Up @@ -406,6 +401,7 @@
<wpf:Card x:Name="PART_PopupContentElement"
Margin="{TemplateBinding DialogMargin}"
wpf:ElevationAssist.Elevation="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ElevationAssist.Elevation)}"
Background="{Binding Tag, RelativeSource={RelativeSource Self}}"
Content="{TemplateBinding DialogContent}"
ContentStringFormat="{TemplateBinding DialogContentStringFormat}"
ContentTemplate="{TemplateBinding DialogContentTemplate}"
Expand All @@ -416,6 +412,7 @@
IsTabStop="False"
Opacity="0"
RenderTransformOrigin=".5,.5"
Style="{TemplateBinding DialogCardStyle}"
Tag="{TemplateBinding DialogBackground}"
TextElement.Foreground="{DynamicResource MaterialDesign.Brush.Foreground}"
UniformCornerRadius="{TemplateBinding DialogContentUniformCornerRadius}">
Expand All @@ -424,23 +421,16 @@
<ScaleTransform x:Name="CardScaleTransform" ScaleX="0" ScaleY="0" />
</TransformGroup>
</wpf:Card.RenderTransform>
<wpf:Card.Style>
<Style TargetType="wpf:Card" BasedOn="{StaticResource {x:Type wpf:Card}}">
<Setter Property="Background" Value="{Binding Tag, RelativeSource={RelativeSource Self}}" />
<Style.Triggers>
<Trigger Property="Tag" Value="{x:Null}">
<Setter Property="Background" Value="{DynamicResource MaterialDesign.Brush.Background}" />
</Trigger>
</Style.Triggers>
</Style>
</wpf:Card.Style>
</wpf:Card>
</Grid>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsOpen" Value="True">
<Setter TargetName="PART_ContentCoverGrid" Property="IsHitTestVisible" Value="True" />
</Trigger>
<Trigger SourceName="PART_PopupContentElement" Property="Tag" Value="{x:Null}">
<Setter TargetName="PART_PopupContentElement" Property="Background" Value="{DynamicResource MaterialDesign.Brush.Background}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
Expand Down
Loading