MaterialDesignInXamlToolkit icon indicating copy to clipboard operation
MaterialDesignInXamlToolkit copied to clipboard

DialogHost Disappears Question

Open KevHoff2020 opened this issue 4 years ago • 1 comments

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 avatar Apr 28 '20 18:04 KevHoff2020

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

KevHoff2020 avatar May 10 '20 19:05 KevHoff2020