【问题标题】:How to show a modal window in windows 10 universal app?如何在 Windows 10 通用应用程序中显示模式窗口?
【发布时间】:2015-10-26 12:04:40
【问题描述】:

当我在 Windows 10 中使用 Mail univesal 应用程序时,当我添加一个帐户(设置->帐户->添加帐户)时,似乎会弹出一个模式窗口来选择一个帐户。我尝试使用 MessageDialog,但我无法将任何自定义内容放入其中。

EDIT:这是截图

有人知道如何实现它或者有一些api可以做到吗?

注意:当这个窗口打开时,你甚至不能最小化/最大化/关闭主窗口。所以,它绝对是一个模态窗口。

【问题讨论】:

    标签: c# xaml uwp windows-10


    【解决方案1】:

    我自己还没用过,但我相信你正在寻找 ContentDialog api。

    var dialog = new ContentDialog() {
        Title = "Lorem Ipsum",
        MaxWidth = this.ActualWidth // Required for Mobile!
        Content = YourXamlContent
    };
    
    
    dialog.PrimaryButtonText = "OK";
    dialog.IsPrimaryButtonEnabled = false;
    dialog.PrimaryButtonClick += delegate {
    };
    
    var result = await dialog.ShowAsync();
    

    msdn 对话指南:link

    msdn ContentDialog API:link

    【讨论】:

      【解决方案2】:

      您可以像这样轻松地创建一个新视图,例如在您的App.xaml.cs

      public static async Task<bool> TryShowNewWindow<TView>(bool switchToView)
      {
          var newView = CoreApplication.CreateNewView();
          int newViewId = 0;
          await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
          {
              var frame = new Frame();
              frame.Navigate(typeof(TView), null);
              Window.Current.Content = frame;
      
              newViewId = ApplicationView.GetForCurrentView().Id;
          });
          var viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
          if (switchToView && viewShown)
          {
              // Switch to new view
              await ApplicationViewSwitcher.SwitchAsync(newViewId);
          }
          return viewShown;
      }
      

      有关更多信息,请查看这两个指南:

      【讨论】:

      • 我知道,也试过了,但是新窗口不是模态窗口。
      • @tao 好吧,你没有要求模态窗口。
      • 对不起,邮件应用看起来像弹出一个模态窗口,你知道如何实现吗?谢谢!
      • @tao 邮件应用不使用模式对话框。从我提供的链接中提取:邮件应用程序使用多个窗口。用户可以在主应用程序窗口中查看消息或打开一个新窗口。例如,当用户想要撰写新消息时,这很有用,但同时使用主窗口搜索其他消息。您应该只对When the user's security might be compromisedWhen the user is about to permanently alter a valuable assetWhen the user is about to delete a valuable assetTo confirm an in-app purchase 使用模式对话框!
      • 这不是一个 MODAL 解决方案。
      【解决方案3】:

      如果使用Template10项目模板,可以使用ModalDialog控件:https://github.com/Windows-XAML/Template10/wiki/Docs-%7C-Controls#modaldialog

      【讨论】:

        猜你喜欢
        • 2017-09-10
        • 1970-01-01
        • 2019-11-16
        • 2011-07-04
        • 1970-01-01
        • 1970-01-01
        • 2012-03-23
        • 2018-11-04
        • 1970-01-01
        相关资源
        最近更新 更多