user9559135
user9559135

Reputation:

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

i'm coding a wpf application using material design

i've a DialogHostnamed 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...

Upvotes: 3

Views: 16003

Answers (4)

David Carrillo
David Carrillo

Reputation: 19

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);
}

Upvotes: 1

Eduardas Šlutas
Eduardas Šlutas

Reputation: 307

In your ViewModel where you host a Dialog, you can simply add these lines:

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

Upvotes: -1

Saad Lembarki
Saad Lembarki

Reputation: 520

Simply you can use this :

view.IsOpen = true;

Upvotes: 2

Mike
Mike

Reputation: 240

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:

https://github.com/ButchersBoy/MaterialDesignInXamlToolkit/blob/2740f14a814896d42032ae0013b765a8a0ec04c3/MainDemo.Wpf/Domain/DialogsViewModel.cs#L36

Upvotes: 3

Related Questions