MaterialDesignInXAML / MaterialDesignInXamlToolkit

Google's Material Design in XAML & WPF, for C# & VB.Net.
http://materialdesigninxaml.net
MIT License
15.02k stars 3.41k forks source link

DialogHost Disappears Question #1778

Open KevHoff2020 opened 4 years ago

KevHoff2020 commented 4 years ago

Hi,

I started using DialogHost to popup a dialog to edit some properties of a currently selected item. However if I switch dialogs while the Edit dialog is displayed, and then return back the Edit dialog disappears and all I see is the gray parent dialog and no way to recover.

In MainWindows.xaml I have:

<materialDesign:DialogHost Identifier="RootDialog">
    <materialDesign:DrawerHost IsLeftDrawerOpen="{Binding ElementName=MenuToggleButton, Path=IsChecked}">

Basically the same structure as the MaterialDesign demo, where I have a DrawerHost to popup
the main menu views that you can select from (Home, Inventory, Billing, etc.)
One of the menu items is "Inventory"

In InventoryViewControl.xaml I have another DialogHost so I can popup edit controls for selected items.

 <materialDesign:DialogHost Identifier="Inventory">

In the ViewModel for the InventoryViewControl I have:

    private async void OnEditOwnerDialog(object _)
    {
        // The view associated with this model is defined in InventoryViewControl.xaml !!
        var model = new OwnerViewControlModel(SelectedOwnerId);
        object result = await MaterialDesignThemes.Wpf.DialogHost.Show(model, "Inventory");
        SaveOrCancel answer = (SaveOrCancel)(result ?? SaveOrCancel.None);
        switch(answer)
        {

In the picture below, showing the RootDialog Drawer menu, the Inventory in the background and the Owner Information from the OwnerViewControl showing.

If I select "Billing" it switches to Billing, and then when I come back to "Inventory" all I see is the gray inventory and the OwnerViewControl is not showing and no way to get it.

Is there an event that I can use to make it pop back up, or would it better to try to prevent the RootDialog from being able to select a different item?

image

Thoughts?

KevHoff2020 commented 4 years ago

While maybe not elegant or proper I was able to overcome by setting the IsEnabled property of the main window to false before calling DialogHost.Show. It also violates the ViewModel not knowing about the View!

        // TODO: Need a way to prevent mainmenu from switching while this is open!
        var mw = (Views.MainWindow)Application.Current.MainWindow;
        mw.dh_RootDialog.IsEnabled = false;
        object result = await MaterialDesignThemes.Wpf.DialogHost.Show(model, "Inventory");