C# 如何在一个网格上创建DialogHost并在另一个网格上调用
我想在WPF应用程序中间找到一个使我的<代码>对话主机的方法,因为我需要在C# 如何在一个网格上创建DialogHost并在另一个网格上调用,c#,.net,wpf,xaml,material-design-in-xaml,C#,.net,Wpf,Xaml,Material Design In Xaml,我想在WPF应用程序中间找到一个使我的对话主机的方法,因为我需要在MigGrase > < /P>中创建它。 <Grid Name="MainGrid"> <materialDesign:DialogHost CloseOnClickAway="True"> <materialDesign:DialogHost.DialogContent> <Grid Margin=&q
<Grid Name="MainGrid">
<materialDesign:DialogHost CloseOnClickAway="True">
<materialDesign:DialogHost.DialogContent>
<Grid Margin="20">
<TextBlock Text="My first Dialog" />
</Grid>
</materialDesign:DialogHost.DialogContent>
</materialDesign:DialogHost>
<Grid Name="Grid1" Width="250" Height ="Auto">
... //MyCode
<Button Name="MyButton" Style="{StaticResource MaterialDesignRaisedButton}" Click="ButtonClick">
...
</Grid>
</Grid>
... //麦可德
...
但是,我将用于调用此对话框主机的按钮位于Grid1
中
有可能吗?如果是,如何使用?您可以使用Material Design提供的routed命令。如果将其指定为按钮的命令
,它将引发一个路由事件,该事件将在可视树中弹出,直到它到达一个对话框主机
,该主机通过显示对话框来处理它。例如:
<Button Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}">
Grid1是一个列,我有几个按钮,图像,文本,字段,复选框,。。。这些Grid1代码在materialDesign:DialogHost
中会有问题吗?@Michael不会,对话框主机只是作为一个容器,应该不会有任何问题。它是这样设计的,以便您可以从内容中执行open命令,这将引发一个路由事件,只有当DialogHost
是相应按钮的父按钮时,才能处理该事件。
<Window ...>
<Grid Name="MainGrid">
<materialDesign:DialogHost CloseOnClickAway="True">
<materialDesign:DialogHost.DialogContent>
<Grid Margin="20">
<TextBlock Text="My first Dialog" />
</Grid>
</materialDesign:DialogHost.DialogContent>
<Grid Name="Grid1" Width="250" Height ="Auto">
<Button Name="MyButton"
Style="{StaticResource MaterialDesignRaisedButton}"
Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}">
</Grid>
</materialDesign:DialogHost>
</Grid>
</Window>