简体   繁体   中英

How to open a material design dialog from the code (.xaml.cs)?

i'm coding a wpf application using material design

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

你可以简单地使用这个:

view.IsOpen = true;

You can set a Name to your DialogHost like: <materialDesign:DialogHost x:Name="MyDialogHost"> .

And then in your XAML.CS file you can use the MyDialogHost.ShowDialog(...) method to show its content like:

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:

var dialog = DialogHost.OpenDialogCommand;
dialog.Execute(null, null);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM