Design and Development of Windows 8 Metro-tile and notification (3)

Source: Internet
Author: User
Add the toast of the Scheduler

ToastIs the"Toast. Regardless of planToastIs the application running,ToastWill appear.ToastIt can be scheduled by the application itself (when the application is running) or in responseWindowsThe notification service is displayed. And,ToastIn addition to text, it can also contain sound.

In this exerciseContoso cookbookAddToast, Simulate a reminder.

Task1-Modify an applicationProgramColumn

To provide plansToastTo add a"Reminder"Command.

1.OpenDefault.html, FindIDForAppBar"DivElement.

2.In the statement"Pin-Recipe"CommandDivAdd the following statement to the application bar:Reminder":

Html

<Buttondata-win-control = "winjs. UI. appbarcommand "data-win-Options =" {ID: 'remind', label: 'reminder', icon: '', Section: 'selection '}"> </button>

3.OpenItemdetailpage. js, InReadyFind"AppBar. showonlycommands".

4.Change this statement to the following:

Javascript

AppBar. showonlycommands (["photo", "video", "pin", "remind", "home"]);

5.Start the application and click a recipe to go to the project details page.

6.Make sure that the application Bar contains"Reminder"Command,5.



Figure5

"Reminder"Command

7.ReturnVisual StudioAnd stop debugging.

 

 

 

Task2-Plan OneToast

The following isReminder"Command to write the Click Event processor and use it to planToast.

1.In Solution ExplorerJSRight-click the folder and use"Add-new item"Command to add the nameEvents. jsOfJavascriptFile.

2.InEvents. jsAdd the followingCode:

Javascript

(Function (){

"Use strict ";

 

VaR toast = windows. UI. events;

 

Winjs. namespace. Define ("notifications ",{

// Schedules a toast notification

Scheduletoast: function (){

// Create a toast notifier

Varnotifier = toast. toastnotificationmanager. createtoastnotifier ();

 

// Make sure notifications are enabled

If (notifier. Setting! = Toast. icationicationsetting. enabled ){

VaR dialog = newwindows. UI. popups. messagedialog ("notifications are currentlydisabled ");

Dialog. showasync ();

Return;

}

 

// Get a toast template and insert a text node containing a message

VaR template = toast. toastnotificationmanager. gettemplatecontent (toast. toasttemplatetype. toasttext01 );

VaR element = template. getelementsbytagname ("text") [0];

Element. appendchild (template. createtextnode ("reminder! "));

 

// Schedule the toast to appear 30 seconds from now

VaR date = new date (). gettime () + 30000 );

Varstn = toast. scheduledtoastnotification (template, date );

Notifier. addtoschedule (STN );

}

});

})();

3.InDefault.htmlAdd the followingScriptElement:

Html

<Scriptsrc = "/JS/events. js"> </SCRIPT>

4.InDefault.html, Add the following highlighted content to"Reminder"Command:

Html

<Buttondata-win-control = "winjs. UI. appbarcommand "data-win-Options =" {ID: 'remind', label: 'reminder', icon: '', Section: 'selection', Onclick: Notifications. scheduletoast} "> </Button>

5.The last task before testing is to enableToastNotification, openPackage. appxmanifestAndApplication UI"Tab,Toast capable"To"Yes"(Figure6).



Figure6

EnableToastNotification

Note:You must enable"Toast capable", The application can be plannedToast. After this setting is enabled, a switch button is displayed on the application's license page, allowing users to open or close accounts. TheScheduletoastThe function can check whether the notification is enabled. If not, a warning is sent to the user.

 

 

Task3-Plan OneToast!

The last task is to test the code and planToast, And viewToast.

1.PressF5Enable the application.

2.Open the selected recipe.

3.Show the application bar and click"Reminder"Button.

4.SwitchMetroStart the screen or other applications, wait about30Seconds,ToastIt will appear (figure7).



Figure7

Contoso cookbookOfToast

5.ClickToastWindow, confirm switch backContoso cookbook.

6.ReturnVisual StudioAnd stop debugging.

Note: ThisArticleThis is the script for Windows 8 online lab on msdn. It is for your reference only. If you want to experience the complete experiment, click the msdn online lab below

Http://msdn.microsoft.com/zh-cn/hh968278

 

 

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.