本文整理汇总了C#中MessageDialog.WaitForButtonPressAsync方法的典型用法代码示例。如果您正苦于以下问题:C# MessageDialog.WaitForButtonPressAsync方法的具体用法?C# MessageDialog.WaitForButtonPressAsync怎么用?C# MessageDialog.WaitForButtonPressAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageDialog
的用法示例。
在下文中一共展示了MessageDialog.WaitForButtonPressAsync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShowMessageAsync
/// <summary>
/// Creates a MessageDialog inside of the current window.
/// </summary>
/// <param name="title">The title of the MessageDialog.</param>
/// <param name="message">The message contained within the MessageDialog.</param>
/// <param name="style">The type of buttons to use.</param>
/// <param name="settings">Optional settings that override the global metro dialog settings.</param>
/// <returns>A task promising the result of which button was pressed.</returns>
public static Task<MessageDialogResult> ShowMessageAsync(this MetroWindow window, string title, string message, MessageDialogStyle style = MessageDialogStyle.Affirmative, MetroDialogSettings settings = null)
{
window.Dispatcher.VerifyAccess();
return HandleOverlayOnShow(settings, window).ContinueWith(z =>
{
return (Task<MessageDialogResult>)window.Dispatcher.Invoke(new Func<Task<MessageDialogResult>>(() =>
{
if (settings == null)
settings = window.MetroDialogOptions;
//create the dialog control
MessageDialog dialog = new MessageDialog(window, settings);
dialog.Message = message;
dialog.Title = title;
dialog.ButtonStyle = style;
SizeChangedEventHandler sizeHandler = SetupAndOpenDialog(window, dialog);
dialog.SizeChangedHandler = sizeHandler;
return dialog.WaitForLoadAsync().ContinueWith(x =>
{
if (DialogOpened != null)
{
window.Dispatcher.BeginInvoke(new Action(() => DialogOpened(window, new DialogStateChangedEventArgs()
{
})));
}
return dialog.WaitForButtonPressAsync().ContinueWith(y =>
{
//once a button as been clicked, begin removing the dialog.
dialog.OnClose();
if (DialogClosed != null)
{
window.Dispatcher.BeginInvoke(new Action(() => DialogClosed(window, new DialogStateChangedEventArgs()
{
})));
}
Task closingTask = (Task)window.Dispatcher.Invoke(new Func<Task>(() => dialog._WaitForCloseAsync()));
return closingTask.ContinueWith<Task<MessageDialogResult>>(a =>
{
return ((Task)window.Dispatcher.Invoke(new Func<Task>(() =>
{
window.SizeChanged -= sizeHandler;
window.metroDialogContainer.Children.Remove(dialog); //remove the dialog from the container
return HandleOverlayOnHide(settings, window);
//window.overlayBox.Visibility = System.Windows.Visibility.Hidden; //deactive the overlay effect
}))).ContinueWith(y3 => y).Unwrap();
});
}).Unwrap();
}).Unwrap().Unwrap();
}));
}).Unwrap();
}