简体   繁体   中英

Popup / Page XAML on another page XAML - UWP App

I have a very simple UWP App, and I'm working on a new update that will bring some design changes. And in this new update I would like to have an "About" button, and when the user clicks the button opens a "popup" that shows more information about the app etc.

That is, what I want is that when you click this button it opens a smaller XAML page above of my XAML home page.

It is possible? If yes, how?

Yes, it is possible. You would like to create new view and switch to this new view.

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);
}

or you can just open a Popup control.

Difference between these two approaches are that Popup control will always overlay application window. New view can be moved out of the app window bounds.

Related links:

Show multiple views for an app

Popup code example

Here you go,

The code which goes in your About Button Click

        contentDialogAboutUs = new ContentDialog();

        Frame framabout = new Frame();

        framabout.Navigate(typeof(AboutUs));

        contentDialogAboutUs.Content = framabout;           

        await contentDialogAboutUs.ShowAsync();

You give information regarding your app in the AboutUs page

You will need to declare the contentDialogAboutUs as static so that it could be used in your AboutUs page to be closed.

public static ContentDialog contentDialogAboutUs;

and in the AboutUs page, close your "popup" using,

        HomePage.contentDialogAboutUs.Hide();

HomePage is my source page from where the AboutUs click was called.

Hope this helped you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM