How to open a material design dialog from the code (.xaml.cs)?
Solution 1
From: 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:
Solution 2
Simply you can use this :
view.IsOpen = true;
Solution 3
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);
}
Admin
Updated on June 04, 2022Comments
-
Admin almost 2 years
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 isCommand="{x:Static materialDesign:DialogHost.OpenDialogCommand}"
but i sought in DialogHost properties and methods and i didn't find anything...