另一页上的Popup / Page XAML XAML - UWP App

时间:2017-12-29 20:04:02

标签: c# xaml uwp uwp-xaml

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

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

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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:1)

你走了,

About Button Click

中的代码
        contentDialogAboutUs = new ContentDialog();

        Frame framabout = new Frame();

        framabout.Navigate(typeof(AboutUs));

        contentDialogAboutUs.Content = framabout;           

        await contentDialogAboutUs.ShowAsync();

您可以在关于我们页面

中提供有关您应用的信息

您需要将contentDialogAboutUs声明为静态,以便可以在关于我们页面中使用它。

public static ContentDialog contentDialogAboutUs;

并在AboutUs页面中,关闭你的" popup"使用,

        HomePage.contentDialogAboutUs.Hide();

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

希望这对你有所帮助。