对话框XAML和材料设计WPF



我正试图在我的WPF应用程序中的xaml页面上弹出一个对话框。我正在使用XAML工具包中的材料设计。

页面位于主窗口的框架内。我想让变暗的对话框背景一直覆盖主窗口上的菜单。(图片示例:对话框背景浏览菜单和完整窗口(

在我的页面上用按钮,我有以下代码

<Button Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}" 
Width="128" Grid.Row="3" Grid.Column="1" >
<Button.CommandParameter>
<system:DateTime></system:DateTime>
</Button.CommandParameter>
Popup
</Button>

然后在我的主窗口上,我有以下代码:

<DataTemplate DataType="{x:Type system:DateTime}">
<StackPanel Margin="16">
<TextBlock>Example!!</TextBlock>
<Button  Margin="0 8 0 0" IsDefault="True" Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" Style="{DynamicResource MaterialDesignRaisedDarkButton}">Close</Button>
</StackPanel>
</DataTemplate>
</ResourceDictionary>
</Window.Resources>

我还包括

xmlns:system="clr-namespace:System;assembly=mscorlib"

当我运行应用程序时,我没有错误,它会打开,但名为"弹出"的按钮被禁用。但当我在材料设计演示中更改时,这段代码确实会在那里运行和工作。

我是XAML的新手,这是我第一个使用这种语言的应用程序,所以非常感谢您的帮助!

您的MainWindow.xaml内容应该看起来像这个

<materialDesign:DialogHost Identifier="RootDialog">
<materialDesign:DialogHost.DialogContent>
<!--dialog content-->
</materialDesign:DialogHost.DialogContent>
<Grid>
<!--your window cotnent-->
</Grid>
</materialDesign:DialogHost>

最新更新