Ma Ning's Windows Phone 7.1 initial experience (3) -- Tile

Source: Internet
Author: User
Tags silver light
    • Implement application Tile
    • Implement secondary Tile
    • Conclusion
    • Openxlive cup Windows Phone game development competition

Author: Ma Ning

When we introduced push notification in the front, we already talked about tile notification. In Windows Phone 7.1, smart tile has been greatly improved. We can not only control the animation display, content, and background switching of tile, but also provide two tile for the same application, such as a weather forecast application.ProgramYou can display multiple tile entries on the homepage of your mobile phone. One is the weather in Beijing, and the other is the weather in Shanghai.

Implement application Tile

The articles on msdn are stinks and long-lived. In fact, they are simple and complicated. I tried to rewrite the example and add it to a button click event of the application:

             // Application tile is always the first tile, even if it is not pinned to start. Shelltile tiletofind = shelltile. activetiles. First (); // Set the properties to update for the Application tile.             // Empty strings for the text values and Uris will result in the property being cleared. Standardtiledata newtiledata = New Standardtiledata {Title = "Title" , Backgroundimage = New Uri ( "Background.png" , Urikind. Relative), Count = 2, backtitle = "Back tilte" , Backbackgroundimage = New Uri ( "Background2.png" , Urikind. Relative), backcontent = "This is backcontent" };// Update the application Tile Tiletofind. Update (newtiledata );

First, we need to reference Microsoft. phone. shell namespace, and then use shelltile. activetiles. first () method to obtain the most important shelltile of the application. each application has at least one tile, so you don't have to worry about this object being empty. Then we create a standardtiledata object and assign values to its attributes. Attributes are divided into two groups. Each group has a background image, title, and content. The display position is shown in. If two groups of tile attributes are set, the tile automatically switches after a period of display. Finally, we call the shelltile object update method and pass the standardtiledata object to complete the tile setting. Backgroundimage and backgroundimage specify the image Uri, which can be a local image or an image from the network. The two images we use are added to the project as content.

When we deploy a program on a device or simulator, the corresponding icon appears in the Application List. We press the icon to display a menu, and select pin to start to display the application icon on the mobile phone homepage.

Run the application and click "button". The tile is updated to a new style. The two backgrounds and content are displayed alternately, as shown in:

Implement secondary Tile

After the application tile is displayed, we need to implement a more complex secondary tile. Of course, we can add multiple tile. When implementing secondary tile, there are two technical points to be implemented: one is to add and display tile; the other is how to differentiate the tile to start the application when the program starts.

First, let's look at how to add the secondary TileCode:

            // Look to see whether the tile already exists and if so, don't try to create it again. Shelltile tiletofind = shelltile. activetiles. firstordefault (x => X. navigationuri. tostring (). Contains ( "Defaulttitle = fromtile" )); // Create the tile if we didn't find that it already exists.              If (Tiletofind = Null ){ // Create the tile object and set some initial properties for the tile.                  // The Count value of 12 shows the number 12 on the front of the tile. Valid values are 1-99.                  // A Count value of 0 indicates that the Count shoshould not be displayed. Standardtiledata newtiledata = New Standardtiledata {backgroundimage = New Uri ( "Background.png" , Urikind. Relative), Title = "Secondary tile" , Count = 12, backtitle = "Back of tile" , Backcontent = "Welcome to the back of the tile" , Backbackgroundimage = New Uri ( "Background2.png" , Urikind. Relative )};// Create the tile and pin it to start. This will cause a navigation to start and a deactivation of our application. Shelltile. Create ( New Uri ( "/Mainpage. XAML? Defaulttitle = fromtile" , Urikind. Relative), newtiledata );} Else {Tiletofind. Delete ();}

First, call shelltile. activetiles. the firstordefault method is used to obtain the shelltile object that contains "defaulttitle = fromtile" in the navigationuri attribute. If the obtained shelltile object is empty, a secondary tile is created. Otherwise, the shelltile Delete method is called, delete the tile.

To create a secondary tile, first create the standardtiledata object and assign values to the displayed parameters. This step is the same as application tile. Then, call the create method of shelltile. The first parameter is Uri, after clicking the tile, you can call the page command line to include parameters. The second parameter is the standardtiledata object, which is used to specify the display style.

Note that if the page command line is incorrect, the application exits directly when you click tile. Due to the failure of debugging, the specific cause cannot be found when you contact this problem for the first time.

Secondary tile:

Next, we need to deal with events that differentiate tile clicks. We need to reload the onnavigatedto method of mainform:

         Protected   Override   Void Onnavigatedto (system. Windows. Navigation. navigationeventargs e ){ String   Value = Null ; If ( This . Navigationcontext. querystring! =Null ){ This . Navigationcontext. querystring. trygetvalue ( "Defaulttitle" , Out   Value ); If ( Value ! = Null ) {Textboxtitle. Text = Value ;} Else {Textboxtitle. Text = "Frommain" ;}} Base . Onnavigatedto (E );}

Use the trygetvalue method of navigationcontext. querystring to obtain the value of the defaulttitle parameter. If this value cannot be obtained, the click is considered to be from the first tile, and the click is from the second tile. We will display the parameters in the text box on the home page. Of course, there can be more complex business logic in actual applications. The interface displays the following results:

Here, we briefly introduce how to add and modify tile content, in addition to how to modify the initial value of tile and specify the time interval of tile updates. We will not introduce it here. You can refer to the smelly and long msdn document. This part is not long and I can guarantee it.


Now, we have finished introducing tile programming in Windows Phone 7.1. Windows Phone uses the Hub Mode to classify features. Therefore, tile is required to have more diverse display modes and forms. In addition, multiple applications can correspond to one tile, and the same application can also correspond to multiple tile, which greatly improves the richness of interaction between the home page and the application.

Of course, the specific tile must be used in actual development to truly understand its advantages and disadvantages.

Openxlive cup Windows Phone game development competition

Openxlive cup Windows Phone game development competition is jointly developed by openxlive and well-known developers in ChinaCommunity: Devdiv, smart machine network, wpmind, Silverlight silver light China and xNa game world, a Windows Phone game development competition.


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: 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.