Example #1
0
    public async Task <Result> ShowDialogAsync <UserInput, Result>(Func <IDialogWindowControl <UserInput, Result> > createDialogFunc)
        where UserInput : UserInputViewModel
        where Result : UserInputResult
    {
        if (Application.Current.Dispatcher == null)
        {
            throw new Exception("The application does not have a valid dispatcher");
        }

        // Create the dialog on the UI thread
        IDialogWindowControl <UserInput, Result> dialog = Application.Current.Dispatcher.Invoke(createDialogFunc);
        string dialogTypeName = dialog.GetType().Name;

        Logger.Trace("A dialog of type {0} was opened", dialogTypeName);

        // Show the dialog and get the result
        Result result = await Dialog.ShowDialogWindowAsync(dialog);

        if (result == null)
        {
            Logger.Warn("The dialog of type {0} returned null", dialogTypeName);
        }
        else if (result.CanceledByUser)
        {
            Logger.Trace("The dialog of type {0} was canceled by the user", dialogTypeName);
        }

        // Return the result
        return(result);
    }
Example #2
0
    public async Task <Result> ShowDialogWindowAsync <UserInput, Result>(IDialogWindowControl <UserInput, Result> windowContent)
        where UserInput : UserInputViewModel
        where Result : UserInputResult
    {
        try
        {
            // Show as a modal with the user input title
            await ShowWindowAsync(windowContent, true, windowContent.ViewModel.Title);

            // Get the dispatcher
            Dispatcher dispatcher = GetDispatcher();

            // Return the result
            return(dispatcher.Invoke(windowContent.GetResult));
        }
        finally
        {
            windowContent.Dispose();
        }
    }