World War I Windows 10 (37) and World War I 37

Source: Internet
Author: User

World War I Windows 10 (37) and World War I 37

[Download source code]


Backwater world war I Windows 10 (37)-control (pop-up class): MessageDialog, ContentDialog



Author: webabcd


Introduction
Controls for Windows 10 (pop-up class)

  • MessageDialog
  • ContentDialog



Example
1. MessageDialog example
Controls/FlyoutControl/MessageDialogDemo. xaml

<Page x: Class = "Windows10.Controls. flyoutControl. messageDialogDemo "xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation "xmlns: x =" http://schemas.microsoft.com/winfx/2006/xaml "xmlns: local =" using: Windows10.Controls. flyoutControl "xmlns: d =" http://schemas.microsoft.com/expression/blend/2008 "xmlns: mc =" http://schemas.openxmlformats.org/markup-compatibility/2006 "mc: ignorable = "d"> <Grid Background = "Transparent"> <StackPanel Margin = "10 0 10"> <TextBlock Name = "lblMsg" Margin = "5"/> <button Name = "btnShowMessageDialogSimple" Margin = "5" Content = "A simple MessageDialog" Click = "success"/> <Button Name = "btnShowMessageDialogCustomCommand" Margin = "5" Content = "MessageDialog" Click = "btnShowMessageDialogCustomCommand_Click"/> </StackPanel> </Grid> </Page>

Controls/FlyoutControl/MessageDialogDemo. xaml. cs

/** MessageDialog-Information dialog box (without inheriting any classes) * Content-Content * Title-Title * Options-option (Windows. UI. popups. * None-normal, default * AcceptUserInputAfterDelay, return the data of the IList <IUICommand> type * DefaultCommandIndex-press the "enter" key, and then run the command * CancelCommandIndex-press the "esc" key to activate this index, command * ShowAsync () to activate this index location-display dialog box, and return the user-triggered command ** IUICommand-command * Label-display text * Id-parameter */using System; using Windows. UI. popups; using Windows. UI. xaml; using Windows. UI. xaml. controls; namespace Windows10.Controls. flyoutControl {public sealed partial class MessageDialogDemo: Page {public MessageDialogDemo () {this. initializeComponent () ;}// a simple MessageDialog private async void upload (object sender, RoutedEventArgs e) {MessageDialog messageDialog = new MessageDialog ("content", "title") is displayed "); await messageDialog. showAsync () ;}// MessageDialog private async void upload (object sender, RoutedEventArgs e) {MessageDialog messageDialog = new MessageDialog ("content ", "title"); messageDialog. commands. add (new UICommand ("Custom command button 1", (command) => {lblMsg. text = string. format ("command label: {0}, id: {1}", command. label, command. id) ;}, "param1"); messageDialog. commands. add (new UICommand ("Custom command button 2", (command) => {lblMsg. text = string. format ("command label: {0}, id: {1}", command. label, command. id) ;}, "param2"); messageDialog. commands. add (new UICommand ("Custom command button 3", (command) => {lblMsg. text = string. format ("command label: {0}, id: {1}", command. label, command. id) ;}, "param3"); messageDialog. defaultCommandIndex = 0; // press the "enter" key to activate the 1st command messageDialog. cancelCommandIndex = 2; // press the "esc" key to activate the messageDialog command 3rd. options = MessageDialogOptions. acceptUserInputAfterDelay; // After the dialog box pops up, you are prohibited from clicking the command button for a short period of time to prevent user misoperation // display the dialog box and return the user-triggered command IUICommand chosenCommand = await messageDialog. showAsync (); lblMsg. text + = Environment. newLine; lblMsg. text + = string. format ("result label: {0}, id: {1}", chosenCommand. label, chosenCommand. id );}}}


2. ContentDialog example
Controls/FlyoutControl/CustomContentDialog. xaml

<ContentDialog x: Class = "Windows10.Controls. FlyoutControl. CustomContentDialog" xmlns =" http://schemas.microsoft.com/winfx/2006/xaml /Presentation "xmlns: x =" http://schemas.microsoft.com/winfx/2006/xaml "Xmlns: local =" using: Windows10.Controls. FlyoutControl "xmlns: d =" http://schemas.microsoft.com/expression/blend/2008 "Xmlns: mc =" http://schemas.openxmlformats.org/markup-compatibility/2006 "Mc: Ignorable =" d "Title =" custom dialog title "PrimaryButtonText =" primary button "SecondaryButtonText =" secondary button "PrimaryButtonClick =" second "SecondaryButtonClick =" second "> <! -- The title of the custom dialog box --> <ContentDialog. titleTemplate> <DataTemplate> <TextBlock Text = "custom dialog title" Foreground = "Red"/> </DataTemplate> </ContentDialog. titleTemplate> <! -- The following is the content of the custom dialog box --> <StackPanel VerticalAlignment = "Stretch" HorizontalAlignment = "Stretch"> <TextBox Name = "email" Header = "Email address"/> <PasswordBox name = "password" Header = "Password"/> <CheckBox Name = "showPassword" Content = "Show password"/> <TextBlock Name = "body" TextWrapping = "Wrap"> <TextBlock. text> content </TextBlock. text> </TextBlock> </StackPanel> </ContentDialog>

Controls/FlyoutControl/CustomContentDialog. xaml. cs

/** Custom ContentDialog */using System. threading. tasks; using Windows. UI. xaml. controls; namespace Windows10.Controls. flyoutControl {public sealed partial class CustomContentDialog: ContentDialog {public CustomContentDialog () {this. initializeComponent () ;}// you have clicked the first private async void ContentDialog_PrimaryButtonClick (ContentDialog sender, ContentDialogButtonClickEventArgs args) {// wait for long-time tasks through GetDeferral, otherwise, even if await is used, it will not wait for ContentDialogButtonClickDeferral deferral = args. getDeferral (); try {await Task. delay (1);} finally {// complete Asynchronous Operation deferral. complete ();} // enable this event to bubble (of course, args. cancel is false by default) args. cancel = false;} // the user clicks the second button private async void ContentDialog_SecondaryButtonClick (ContentDialog sender, ContentDialogButtonClickEventArgs args) {// use GetDeferral () to wait for long-time tasks, otherwise, even if await is used, it will not wait for ContentDialogButtonClickDeferral deferral = args. getDeferral (); try {await Task. delay (1);} finally {// complete Asynchronous Operation deferral. complete ();} // enable this event to bubble (of course, args. cancel is false by default) args. cancel = false ;}}}

Controls/FlyoutControl/ContentDialogDemo. xaml

<Page x: Class = "Windows10.Controls. flyoutControl. contentDialogDemo "xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation "xmlns: x =" http://schemas.microsoft.com/winfx/2006/xaml "xmlns: local =" using: Windows10.Controls. flyoutControl "xmlns: d =" http://schemas.microsoft.com/expression/blend/2008 "xmlns: mc =" http://schemas.openxmlformats.org/markup-compatibility/2006 "mc: ignorable = "d"> <Grid Background = "Transparent"> <StackPanel Margin = "10 0 10"> <Button Name = "btnShowDialog" Margin = "5" Content =" A standard dialog box "Click =" btnShowDialog_Click "/> <Button Name =" btnShowCustomDialog "Margin =" 5 "Content =" pop up a custom dialog box "Click =" btnShowCustomDialog_Click" /> <TextBlock Name = "lblMsg" Margin = "5"/> </StackPanel> </Grid> </Page>

Controls/FlyoutControl/ContentDialogDemo. xaml. cs

/** ContentDialog-content dialog box (inherited from ContentControl, see/Controls/BaseControl/ContentControlDemo/) * FullSizeDesired-whether to display the dialog box in full screen * Title, titleTemplate-title of the dialog box (you can customize the style) * Content, ContentTemplate-Content of the dialog box (you can customize the style) * PrimaryButtonText-text displayed by the first button in the dialog box * SecondaryButtonText-text displayed by the second button in the dialog box * PrimaryButtonCommand, PrimaryButtonCommandParameter, SecondaryButtonCommand, secondaryButtonCommandParameter-button command and command parameter ** events triggered when PrimaryButtonClick-the first button is pressed * SecondaryButtonClick-events triggered when the second button is pressed * Closed, Closing, opened-events ** ShowAsync ()-pop-up dialog box * Hide ()-Hide dialog box ** Note: For custom content dialog box, see CustomContentDialog. xaml */using System; using Windows. UI. xaml; using Windows. UI. xaml. controls; namespace Windows10.Controls. flyoutControl {public sealed partial class ContentDialogDemo: Page {public ContentDialogDemo () {this. initializeComponent ();} private async void btnShowDialog_Click (object sender, RoutedEventArgs e) {ContentDialog dialog = new ContentDialog () {Title = "dialog title", Content = "alog dicontent content, dialog content, dialog content ", FullSizeDesired = true, PrimaryButtonText =" PrimaryButton ", SecondaryButtonText =" SecondaryButton "}; dialog. primaryButtonClick + = dialog_PrimaryButtonClick; dialog. secondaryButtonClick + = dialog_SecondaryButtonClick; // In the displayed dialog box, the returned value is the user's selection result/** ContentDialogResult. primary-select the first button * ContentDialogResult. secondary-select the second button * ContentDialogResult. none-the user has not selected (the system's "return" button is pressed) */ContentDialogResult result = await dialog. showAsync (); if (result = ContentDialogResult. primary) {lblMsg. text + = "select the first button"; lblMsg. text + = Environment. newLine;} else if (result = ContentDialogResult. secondary) {lblMsg. text + = "select the second button"; lblMsg. text + = Environment. newLine;} else if (result = ContentDialogResult. none) {lblMsg. text + = "no selection button"; lblMsg. text + = Environment. newLine ;}} void dialog_PrimaryButtonClick (ContentDialog sender, ContentDialogButtonClickEventArgs args) {lblMsg. text + = "click the first button"; lblMsg. text + = Environment. newLine;} void dialog_SecondaryButtonClick (ContentDialog sender, ContentDialogButtonClickEventArgs args) {lblMsg. text + = "click the second button"; lblMsg. text + = Environment. newLine;} // The Custom dialog box async private void btnShowCustomDialog_Click (object sender, RoutedEventArgs e) {// instantiate custom dialog box CustomContentDialog contentDialog = new CustomContentDialog () appears, the returned value is the user's selection result/** ContentDialogResult. primary-select the first button * ContentDialogResult. secondary-select the second button * ContentDialogResult. none-the user has not selected (the system's "return" button is pressed) */ContentDialogResult result = await contentDialog. showAsync (); if (result = ContentDialogResult. primary) {lblMsg. text + = "select the first button"; lblMsg. text + = Environment. newLine;} else if (result = ContentDialogResult. secondary) {lblMsg. text + = "select the second button"; lblMsg. text + = Environment. newLine;} else if (result = ContentDialogResult. none) {lblMsg. text + = "no selection button"; lblMsg. text + = Environment. newLine ;}}}}



OK
[Download source code]

Related Article

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.