Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show a modal window in windows 10 universal app?

When I use Mail univesal app in windows 10, when i add an account (setting->accounts->add account), it seems popup a modal window to choose an account. I try to use MessageDialog, but i can't put any custom content into it.

EDIT : this is the screenshot screenshot

Is someone knows how to implement it or there is some api can do it?

Note: When this window open, you even can't Minimize/Maximize/Close the main Window. So, it is definitely a modal window.

like image 288
tao Avatar asked Aug 04 '15 07:08

tao


Video Answer


2 Answers

I haven't used it myself yet but i believe you're looking for 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();

content dialog

msdn guidlines for dialogs: link

msdn ContentDialog API: link

like image 61
Liero Avatar answered Oct 23 '22 23:10

Liero


You can easily create a new view like this, for example in your 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;
}

For further information, take a look at those two guides:

  • Guidelines for multiple windows
  • Quickstart: Creating multiple windows for an app (XAML)
like image 45
Herdo Avatar answered Oct 24 '22 01:10

Herdo