[英]How to open a material design dialog from the code (.xaml.cs)?
i'm coding a wpf application using material design我正在使用材料设计编写 wpf 应用程序
i've a DialogHost
named dialog and i want to open and show its content from the code (.xaml.cs), in XAML the command is Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}"
but i sought in DialogHost properties and methods and i didn't find anything...我有一个名为 dialog 的DialogHost
,我想从代码 (.xaml.cs) 打开并显示其内容,在 XAML 中,命令是Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}"
但我在 DialogHost 中寻找属性和方法,我没有找到任何东西......
From: https://github.com/ButchersBoy/MaterialDesignInXamlToolkit/wiki/Dialogs#dialoghostshow来自: https : //github.com/ButchersBoy/MaterialDesignInXamlToolkit/wiki/Dialogs#dialoghostshow
var result = await DialogHost.Show(view, "RootDialog", ClosingEventHandler);
If you'd like a concrete example, check out the demo source:如果你想要一个具体的例子,请查看演示源:
https://github.com/ButchersBoy/MaterialDesignInXamlToolkit/blob/2740f14a814896d42032ae0013b765a8a0ec04c3/MainDemo.Wpf/Domain/DialogsViewModel.cs#L36 https://github.com/ButchersBoy/MaterialDesignInXamlToolkit/blob/2740f14a814896d42032ae0013b765a8a0ec04c3/MainDemo.Wpf/Domain/DialogsViewModel.cs#L36
你可以简单地使用这个:
view.IsOpen = true;
You can set a Name to your DialogHost like: <materialDesign:DialogHost x:Name="MyDialogHost">
.您可以为 DialogHost 设置一个名称,例如: <materialDesign:DialogHost x:Name="MyDialogHost">
。
And then in your XAML.CS file you can use the MyDialogHost.ShowDialog(...)
method to show its content like:然后在您的 XAML.CS 文件中,您可以使用MyDialogHost.ShowDialog(...)
方法来显示其内容,例如:
private void MyButton_Click(object sender, RoutedEventArgs e)
{
MyDialogHost.ShowDialog(MyDialogHost.DialogContent);
}
In your ViewModel where you host a Dialog, you can simply add these lines:在您托管 Dialog 的 ViewModel 中,您只需添加以下几行:
var dialog = DialogHost.OpenDialogCommand;
dialog.Execute(null, null);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.