0

In my app, I'm loading a DocumentViewer for previewing and printing. Because loading can take up to a few seconds, I would like to display a ProgressDialog. The logic is this: display ProgressDialog, create and display DocumentViewer, close ProgressDialog.

The problem is that when closing the dialog, the focus returns to the MainWindow, instead of remaining to the DocumentViewer window. I think it's because the dialog CloseAsync(). I've tried calling Focus(), Activate(), Show(), setting TopMost = true, setting the owner of the child window, but, although the window is displayed in front of the parent, the focus still returns to the parent. The only way to I restored the focus to the child was by doing a programmatic click inside the child window, in ProgressDialogController.Closed event, but the disadvantage is that there is an ugly transition (child initially appears in front, then parent, then child again).

Can CloseAsync() be avoided? Or how to close MahApps ProgressDialog without losing focus on child control?

UPDATE

I'm using MahApps 1.3.0.157. The code I'm using in Viewmodel:

public async void PrintLogExecute()
    {
            await DialogService.ShowProgressDialog(Properties.Resources.loading_message_box_title, Properties.Resources.loading_message_box_text);
            ReportingClass.PrintDataGrid(LogEntries);
            DialogService.CloseProgressDialog();
    }

The DialogService class:

static class DialogService
{

    public static async Task ShowProgressDialog(string dialogTitle, string message)
    {
        var metroWindow = (GetMainWindow() as MetroWindow);
        controller = await metroWindow.ShowProgressAsync(dialogTitle, message);
        controller.SetIndeterminate();
    }

    public static void CloseProgressDialog()
    {
        controller.CloseAsync();
    }

    private static Window GetMainWindow()
    {
        return Application.Current.Windows[0];
    }
}

When executing PrintLogExecute(), the document previewer firstly appears in front of the main window and immediately after this, when executing DialogService.CloseProgressDialog() it goes to background. Like I said, the only way I restored the focus to the child was by doing a programmatic click inside the child window, in ProgressDialogController.Closed event.

2 Answers 2

0

maybe this helps you.

<mahApps:MetroWindow x:Class="WakeOnLanV2.MainWindow"
                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:commands="clr-namespace:WakeOnLanV2.Commands"
                     xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
                     xmlns:mahApps="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
                     xmlns:viewModels="clr-namespace:WakeOnLanV2.ViewModels"
                     xmlns:views="clr-namespace:WakeOnLanV2.Views"
                     xmlns:wakeOnLan="clr-namespace:WakeOnLanV2"
                     x:Name="MainView" >
     <Grid>
        <Grid>
            <!--  main grid  -->
        </Grid>

        <mahApps:ProgressRing Width="150"
                              Height="150"                                 
                              Canvas.ZIndex="110"                                  
                              IsActive="{Binding Path=IsBusy,
                                                 UpdateSourceTrigger=PropertyChanged,
                                                 FallbackValue=False}"
                              IsLarge="True" />

    </Grid>
</mahApps:MetroWindow>

The ring is under the MainGrid to keep it in the foreground.

1
  • Thanks for this alternative. However, I would like to use the ProgressDialog.
    – Cristian M
    Jun 2, 2016 at 10:10
0

I got the answer from GitHub:

https://github.com/MahApps/MahApps.Metro/issues/2532

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.