【问题标题】:Popup / Page XAML on another page XAML - UWP App另一个页面上的弹出/页面 XAML XAML - UWP 应用
【发布时间】:2018-06-10 04:56:21
【问题描述】:

我有一个非常简单的 UWP 应用,我正在开发一个新的更新,它将带来一些设计更改。在这个新的更新中,我想要一个“关于”按钮,当用户单击该按钮时,会打开一个“弹出窗口”,显示有关应用程序等的更多信息。

也就是说,我想要的是,当您单击此按钮时,它会在我的 XAML 主页上方打开一个较小的 XAML 页面。

有可能吗?如果是,怎么做?

【问题讨论】:

    标签: c# xaml uwp uwp-xaml


    【解决方案1】:

    是的,这是可能的。您想创建新视图并切换到此新视图。

    private async void Button_Click(object sender, RoutedEventArgs e)
    {
        CoreApplicationView newView = CoreApplication.CreateNewView();
        int newViewId = 0;
        await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
        {
            Frame frame = new Frame();
            frame.Navigate(typeof(SecondaryPage), null);   
            Window.Current.Content = frame;
            // You have to activate the window in order to show it later.
            Window.Current.Activate();
    
            newViewId = ApplicationView.GetForCurrentView().Id;
        });
        bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
    }
    

    或者您可以只打开一个Popup 控件。

    这两种方法的区别在于 Popup 控件总是覆盖应用程序窗口。新视图可以移出应用窗口边界。

    相关链接:

    Show multiple views for an app

    Popup code example

    【讨论】:

      【解决方案2】:

      给你,

      About Button Click 中的代码

              contentDialogAboutUs = new ContentDialog();
      
              Frame framabout = new Frame();
      
              framabout.Navigate(typeof(AboutUs));
      
              contentDialogAboutUs.Content = framabout;           
      
              await contentDialogAboutUs.ShowAsync();
      

      您在关于我们页面中提供有关您的应用的信息

      您需要将contentDialogAboutUs 声明为静态,以便在您要关闭的AboutUs页面中使用它。

      public static ContentDialog contentDialogAboutUs;
      

      然后在 AboutUs 页面中,使用,关闭您的“弹出窗口”,

              HomePage.contentDialogAboutUs.Hide();
      

      HomePage 是我调用 AboutUs 点击的源页面。

      希望这对您有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-07-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多