[Wanli journey-Windows App development] dynamic tile, journey app

Source: Internet
Author: User

[Wanli journey-Windows App development] dynamic tile, journey app

What is dynamic tile? I believe you have been familiar with Windows 8/8. 1/10 for so long.

For example, what is a small tile, a medium tile, a wide tile, a large tile, and a Logo of the app store here, you can choose a suitable image based on different resolutions below.

The following is a function to update the tile page. This is the XML part of the page.

<StackPanel Margin = "12"> <StackPanel Orientation = "Horizontal"> <TextBlock FontSize = "28" Text = "select a template: "VerticalAlignment =" Center "/> <ComboBox x: Name =" comboBoxTile "Width =" 400 "SelectionChanged =" comboBoxTile_SelectionChanged "/> </StackPanel> <TextBox x: name = "textBoxXML" TextWrapping = "Wrap" FontSize = "22" Header = "XML document" Width = "420" Height = "320" HorizontalAlignment = "Left" Margin = "12 "/> <Button Name =" btnTile "Content =" Update tile "Click =" btnTile_Click "Style =" {StaticResource StyleToastButton} "/> </StackPanel>

In the Main function of the background code, obtain the TileTemplateType enumeration and bind it to ComboBox.

var itemsTile = Enum.GetNames(typeof(TileTemplateType));this.comboBoxTile.ItemsSource = itemsTile;

The code below is really similar to the previous Toast, so I wrote these two sections together. In the Click Event of the Button, create an XML file as before and load it to the instance of the TileNotification class. The last is the TileUpdateManager class, that is, tile update.

private void btnTile_Click(object sender, RoutedEventArgs e){    if (this.textBoxXML.Text == "")          return;    XmlDocument xdoc = new XmlDocument();    xdoc.LoadXml(this.textBoxXML.Text);    TileNotification tileNotifi = new TileNotification(xdoc);    TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotifi);}private void comboBoxTile_SelectionChanged(object sender, SelectionChangedEventArgs e){    TileTemplateType tileTemplate = (TileTemplateType)Enum.Parse(typeof(TileTemplateType),        this.comboBoxTile.SelectedItem as string);    XmlDocument xdoc = TileUpdateManager.GetTemplateContent(tileTemplate);    this.textBoxXML.Text = xdoc.GetXml();}

Of course, if your APP is not satisfied with a tile, you can also create a second tile!

It is still similar to the Toast notification XML, and it also has many attributes ......

Arguments: This string parameter is passed to the OnLaunched method of the Application class when the Application is started with a secondary tile. In this way, the Application can perform specific operations based on the input parameters.

BackgroundColor: Set the background color of the tile.

DisplayName and ShortName: Set the text displayed on the tile.

Logo: Set the tile icon and use Uri.

ForegroundText: The color of the text on the tile. Available options include dark color and light color.

TileID: sets the unique ID of the tile. Before creating a new tile, use SecondaryTile. Exists to determine whether it already Exists.

In the Click Event of the Button for adding the second tile:

Private async void btnCreateTile (object sender, RoutedEventArgs e) {if (SecondaryTile. exists (textTileID. text) {textBlockMsg. text = "this ID tile already exists"; return;} Uri uriImg = new Uri ("ms-appx: // Assests/uriImg.png ");...... ...... // Create the second tile SecondaryTile secTile = new SecondaryTile (); this. tag = secTile; secTile. displayName = textBlockDisplayName. text; secTile. tileID = textBlockID. text; secTile. arguments = "second"; // used later // sets the icon secTile. visualElements. backgroundColor = Windows. UI. colors. gold ;...... ...... Bool r = await secTile. RequestCreateAsync (); textBlockMsg. Text = r = true? "The tile creation is successful.": "The tile creation failed."; // return the test result.

If you want to click the second tile to navigate to a specific page, you need to override the OnNavigatedTo method of the page.

preteced async override void OnNavigatedTo(NavigationEventArgs e){    if(e.Parameter is Windows.ApplicationModel.Activation.LaunchActivatedEventArgs)    {        var arg=e.Parameter as Windows.ApplicationModel.Activation.LaunchActivateEventArgs;        ……    }}if(rootFrame.Content==null){    if(e.Arguments=="second")        rootFrame.Navigate(typeof(OtherPage),e);    else        rootFrame.Navigate(typeof(MainPage));}

Here the parameter "second" is the Arguments set above. Its function is here.

Thank you for your visit and hope to help you. Welcome to your attention, favorites, and comments.

For this article to get an axe and a question, please indicate the source:
Http://blog.csdn.net/nomasp

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.