/// <summary> /// Event handler for displaying a message to the user /// </summary> private async void UserPrompt_MessageValueChanged(object sender, UserPromptMessageChangedEventArgs e) { try { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High, async() => { var contentDialog = new ContentDialog() { Title = e.MessageTitle, Content = e.Message, }; if (e.IsError) { contentDialog.PrimaryButtonText = Shared.Properties.Resources.GetString("GenericAffirmativeButton_Content"); } else { contentDialog.PrimaryButtonText = string.IsNullOrEmpty(e.AffirmativeActionButtonContent) ? Shared.Properties.Resources.GetString("GenericAffirmativeButton_Content") : e.AffirmativeActionButtonContent; contentDialog.SecondaryButtonText = string.IsNullOrEmpty(e.NegativeActionButtonContent) ? Shared.Properties.Resources.GetString("GenericNegativeButton_Content") : e.NegativeActionButtonContent; contentDialog.DefaultButton = ContentDialogButton.Primary; } contentDialog.Closed += (s, ea) => { if (ea.Result == ContentDialogResult.Primary) { UserPromptMessenger.Instance.RaiseResponseValueChanged(true); } else { UserPromptMessenger.Instance.RaiseResponseValueChanged(false); } }; try { await contentDialog.ShowAsync(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } }); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); Environment.FailFast("Couldn't display error message.", ex); } }
/// <summary> /// Handles changes in messages coming from the viewmodel by opening a dialog box and prompting the user for answer /// </summary> private void DialogBoxMessenger_MessageValueChanged(object sender, UserPromptMessageChangedEventArgs e) { Dispatcher.Invoke(() => { DialogBoxWindow dialogBox = new DialogBoxWindow(e.Message, e.MessageTitle, e.IsError, e.StackTrace, e.AffirmativeActionButtonContent, e.NegativeActionButtonContent); dialogBox.Closing += DialogBox_Closing; dialogBox.ShowDialog(); }); }