Practical development tips for Windows Phone (18): Use systemtray to display global message reminders

Source: Internet
Author: User

In versions earlier than Windows Phone 7 (nodo ),ProgramDisplays message reminders or progress prompts. Generally, a dedicated container (such as a grid) is placed at the top of the page, which contains some text and ceceprogressbar. In mango, one more option is to display text and progress bars in systemtray. For example, systemtray displays the status bar of the system information, including the current signal, power, and time.

 

Jeff wrote an article using systemtray. This article is based on some extensions. I will use two demos to demonstrate how to use systemtray.

Demo1: The page contains two buttons: the previous button and the next one. clicking the next button will display the next information. clicking the previous button will display the previous information. The final result is as follows:

 

As jeff mentioned in his blog, we need to create a class for displaying systemtray and instantiate this class during rootframe instantiation (in app. XAML. about 120 rows in CS ). Then, a singleton instance is provided to the outside world.

 

Let's take a look at how the instance "hijack" rootframe: In the initialization method, we will instantiate a progressindicator, which is used to display text and progress on systemtray. Register a page navigation event. If the current page is not empty, set the system bar to true and set its foreground color, background color, and transparency. In its constructor, an array is instantiated. This array is used to display the ad content:

 

Of course, we need to provide an interface so that we can control the currently displayed content in the code behind of the page:

 

The index of the current array is provided here. InCodeChanging the index ++ or -- changes the text of the current progressindicator. Then let's see how the page is controlled.

 

Two buttons are placed on the page, and the two buttons have corresponding click events:

 

At the same time, it is noted that the availability of the button is bound to the attribute, and the data source has been set in the page constructor. Let's take a look at how converter writes it:

 

The above code is the converter corresponding to the "previous" button, that is, when the current index is less than or equal to 0, the button is not available, and the availability of the "Next" button is also set. ,

 Demo2:

We place a togglebutton on the page, that is, the button that can respond to the switch, such:

 

Implemented functions:After you click Open AD, the system will display an ad every 2 seconds. After you click Close AD, the system bar will automatically hide it..

In Windows Phone, we usually use dispatchertimer to execute an action every few seconds.

Like demo1, we need to provide an interface in globalloading to control whether to display advertisements:

 

Here, I provide an attribute of the bool value to the outside. If it is set to true, timer will be started to do something. If it is set to false, timer will be stopped. Careful friends can notice that here I will set the progressindicator's visibility to whether or not to play the ad. Let's take a look at how timer is made:

 

In timer, a current index is set. After the index is played every two seconds, it is automatically added. After traversing the array, It is reset to 0. The following code is very simple for external calls:

 

Source codeDownload:

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.