当前位置: 首页>>代码示例>>C#>>正文


C# InputDialog.WaitForButtonPressAsync方法代码示例

本文整理汇总了C#中InputDialog.WaitForButtonPressAsync方法的典型用法代码示例。如果您正苦于以下问题:C# InputDialog.WaitForButtonPressAsync方法的具体用法?C# InputDialog.WaitForButtonPressAsync怎么用?C# InputDialog.WaitForButtonPressAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在InputDialog的用法示例。


在下文中一共展示了InputDialog.WaitForButtonPressAsync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShowInputAsync

        /// <summary>
        /// Creates a InputDialog 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="settings">Optional settings that override the global metro dialog settings.</param>
        /// <returns>The text that was entered or null (Nothing in Visual Basic) if the user cancelled the operation.</returns>
        public static Task<string> ShowInputAsync(this MetroWindow window, string title, string message, MetroDialogSettings settings = null)
        {
            window.Dispatcher.VerifyAccess();
            return HandleOverlayOnShow(settings, window).ContinueWith(z =>
                {
                    return (Task<string>)window.Dispatcher.Invoke(new Func<Task<string>>(() =>
                        {
                            if (settings == null)
                                settings = window.MetroDialogOptions;

                            //create the dialog control
                            InputDialog dialog = new InputDialog(window, settings);
                            dialog.Title = title;
                            dialog.Message = message;
                            dialog.Input = settings.DefaultText;

                            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<string>>(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();
        }
开发者ID:jinlook,项目名称:MahApps.Metro,代码行数:67,代码来源:DialogManager.cs


注:本文中的InputDialog.WaitForButtonPressAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。