Win10 UWP Messagedialog and Contentdialog

Source: Internet
Author: User

I previously developed a software winmarkdown, this software in the shutdown need to prompt the user has not saved things, need to save, if the user chooses to quit, then the data stored.

In the Metro program, there is no traditional window, when we need to interact with the message prompt, in the Win8 era, the introduction of a messagedialog to replace the usual MessageBox.

I'm in MainPage, hang up.App.Current.Suspending += suspend;

        Private Async void Suspend(Objectsender, Windows.ApplicationModel.SuspendingEventArgs e) {suspendingdeferral deferral = E.suspendingoper ation.            Getdeferral (); Messagedialog Message_dialog =NewMessagedialog ("Currently running, OK exit","Exit"); MESSAGE_DIALOG.COMMANDS.ADD (NewUicommand ("OK", cmd = {},"Exit")); MESSAGE_DIALOG.COMMANDS.ADD (NewUicommand ("Cancel", cmd = {})); Message_dialog. Defaultcommandindex =0; Message_dialog. Cancelcommandindex =1; Iuicommand result =awaitMessage_dialog. Showasync ();if(result.) Id as string=="Exit") {} deferral.complete (); }

SuspendingDeferral deferral = e.SuspendingOperation.GetDeferral();Hang up and do it untildeferral.Complete();

            new MessageDialog("当前还在运行,确定退出""退出");            message_dialog.Commands.Add(new UICommand("确定""退出"));            message_dialog.Commands.Add(new UICommand("取消", cmd => { }));

Two buttons, one OK, one cancel, can Uicommand ID as clicked, which button is clicked

MessageDialog.DefaultCommandIndex按ESC选择按钮MessageDialog.CancelCommandIndex按enter按钮
            result = await message_dialog.ShowAsync();            if (resultasstring"退出")            {            }

Program to debug hangs, Need life cycle, click Hang

We'll press ENTER and we'll click OK.

And we don't feel enough about the Messagedialog feature, Contentdialog can define complex XAML customizations

We'll change the Messagedialog to Contentdialog.

            new ContentDialog()            {                "退出",                "当前还在运行,确定退出",                "确定",                "取消",                true,            };            (_s, _e) => { };            await content_dialog.ShowAsync();

<UserControl    x:class="Produproperty.content"    xmlns="Http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="Http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:local="Using:produproperty"    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"    XMLNS:MC="http://schemas.openxmlformats.org/markup-compatibility/2006"    mc:ignorable="D"    D:designheight="+"    D:designwidth=" the">    <Grid>        <grid.rowdefinitions>            <rowdefinition></rowdefinition>            <rowdefinition></rowdefinition>        </grid.rowdefinitions>        <TextBlock grid.row="0" Text="Currently running, OK exit"></TextBlock>        <CheckBox grid.row="1" Content="Save"></CheckBox>    </Grid></UserControl>
            new ContentDialog()            {                "退出",                new content(),                "确定",                "取消",                false,            };            (_s, _e) => { };            await content_dialog.ShowAsync();

See:
Http://www.cnblogs.com/TianFang/p/4857205.html

Win10 UWP Messagedialog and Contentdialog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.