[Win10 Development] Toast notification-foreground activation, win10toast

Source: Internet
Author: User

[Win10 Development] Toast notification-foreground activation, win10toast

In the previous article, we introduced the general Toast notification template and instance display, so this article will talk about the front-end activation of Toast.

The first is the xaml interface, which is very simple. We put a Button and TextBlock to display the content transmitted by the Toast notification.

<StackPanel VerticalAlignment = "Center"> <Button Content = "notification" verticalignment = "Top" HorizontalAlignment = "Center" Click = "Button_Click"/> <TextBlock Name = "getInfo" Height = "60" FontSize = "40" HorizontalAlignment = "Center" Foreground = "Red" FontFamily = "Microsoft YaHei"/> </StackPanel>

Then construct the Toast architecture. These things have been mentioned in the previous article and will not be detailed here.

String xml = "<toast>" + "<visual>" + "<binding template = \" ToastGeneric \ ">" + "<text> notification </text>" +" <text> Toast Test </text> "+" <text> enter your name </text> "+" </binding> "+" </visual> "+ "<actions>" + "<input id = \" name \ "type = \" text \ "placeHolderContent = \" Enter name \ "/>" + "<action content = \ "OK \" arguments = \ "OK \" activationType = \ "foreground \"/> "+" <action content = \ "cancel \" arguments = \ "cancel \ "/>" + "</actions>" + "</toast> ";

Next, let the Toast notification be displayed.

            XmlDocument doc = new XmlDocument();            doc.LoadXml(xml);            ToastNotification notification = new ToastNotification(doc);            
ToastNotificationManager.CreateToastNotifier().Show(notification);

Here, we first write a ShowText method to pass the Toast notification parameters to the Text attribute of the TextBlock control.

        public void ShowText(string msg)        {            getInfo.Text = msg;        }

 

Because the Application is activated on the foreground, we need to activate the Application class. In the App class, we rewrite the OnActivated method, which is written in the App. xaml. cs file. The complete code is as follows, which will be explained in detail later.

Protected override void OnActivated (IActivatedEventArgs args ){
// Determine whether it is the if (args. kind = ActivationKind. toastNotification) {// conversion parameter type toastnotifactivactivatedeventargs toastargs = (ToastNotificationActivatedEventArgs) args; // obtain the page reference Frame root = Window. current. content as Frame; if (root = null) {root = new Frame (); Window. current. content = root;} if (root. content = null) {root. navigate (typeof (MainPage);} MainPage = (MainPage) root. content; String activeargs = toastargs. argument; if (activeargs = "OK") {// obtain the user input string name = toastargs. userInput ["name"] as string; page. showText ($ "Your name is: {name}");} else {page. showText ("No information is collected. ") ;}} Window. Current. Activate ();}

First, we need to determine whether the Kind attribute of the method parameter is activated by the Toast notification, and then convert the method parameter to the ToastNotificationActivatedEventArgs type, in this case, the value of toast's Argument attribute is the arguments defined in Toast XML. The value is "OK" and "cancel". The value of UserInput is the content entered by the input element, it is a dictionary type. We can get the content entered by the user in the text box. We also need to obtain the MainPage and pass the Toast notification parameters to the TextBlock control of MainPage.

Well, we have done well in the activation part of the front-end. Finally, let's take a look at the results.

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.