对话框 XAML 和 Material 设计 WPF

Dialog XAML and Material Design WPF

我正在尝试在我的 WPF 应用程序中的 xaml 页面上弹出一个对话框。我正在使用 Material Design In XAML Toolkit.

该页面位于主页面 window 的框架内。我想让变暗的对话框背景一直覆盖主 window 中的菜单。 (图片示例:Dialog background going over menu and full window)

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

<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>

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

        <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"

当我 运行 我的应用程序没有错误并且它打开时,但名为 "Popup" 的按钮被禁用。但是这段代码确实 运行 并且在我在那里更改它时在 Material Design Demo 中工作。

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

您的 MainWindow.xaml 内容应如下所示

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