How to change the Tile contents in run time in windows 8 metro apps?

Answered How to change the Tile contents in run time in windows 8 metro apps?

  • 2012年7月27日 10:17
     
     

      This is a function called updatetilewithimage.This works fine when written on a button click.It changes the image and content.But I need this to work as soon a the Windows 8 launches.App.xml.cs constructor is called after the tile updates and splash screen is loaded.Where should I wrote this page of code ?

    Function -updatetilewithimage

    ITileWideSmallImageAndText04tilecontent = TileContentFactory.CreateTileWideSmallImageAndText04();

    tilecontent.TextHeading.Text = "system not safe";

    tilecontent.TextBodyWrap.Text = "duios molis sulekha";

    tilecontent.Image.Src = "ms-appx:///images/tiles_notinstalled_notsafe_green.png";

    tilecontent.Image.Alt = "Red Image";

    ITileSquareImagesquarecontent = TileContentFactory.CreateTileSquareImage();

    squarecontent.Image.Src = "ms-appx:///images/maroon_tile.png";

    squarecontent.Image.Alt = "Gray image";

    tilecontent.SquareContent = squarecontent;

    TileUpdateManager.CreateTileUpdaterForApplication().Update(tilecontent.CreateNotification());

    }

     

             


               

               

               

すべての返信

  • 2012年7月27日 10:28
     
     
    Well you can put it in OnLaunched event handler of App, or OnNavigatedTo (you should use LoadState if you are using LayoutAwarePage) on your first page (e.g. MainPage.xaml.cs

    Can Bilgin
    Blog CompuSight

  • 2012年7月29日 14:01
     
     

    Hi.

    I have tried both the OnLaunched event handler of App, or OnNavigatedTo in both App.xml and MainPage.xml but it didn't worked as they are called at later stage.

    The mail tile logo,image and content are decided through package.appxmanifest.I need to call any function through an other event so that as the windows 8 launch according to the condition the details changes on the mail tile.

    Let me know how to override the package.appxmanifest or call any fuction/API through it in a C# project?If possible please let me know an sample code.

    - Sulekha

  • 2012年7月30日 6:11
    モデレータ
     
     

    Hi Sulekha,

    If I understand your issue correctly, actually you would like to overwrite the default tile which created in the package.appmanifest file. If so, in my opinion there is no way to do that.

    As far as I know that, the default tile is defined in the package.appmanifest file and displayed on the Start screen when your app is first installed. I do not think you are able to define it in another file.

    Please correct me if my understanding is incorrect.


    Vicky Song [MSFT]
    MSDN Community Support | Feedback to us

  • 2012年7月30日 6:57
     
     

    Hi,

    Your understanding is correct.I need to change the main tile image and text as soon as the Windows 8 launches.I need to call any function and according to the return parameters I need to change the background color and content of the main tile.And for this I am not getting any events as the application constructors are called after the splash screen and main tile is loaded.

    But in windows 8 metro apps I have seen that the tile image and contents changes periodically.So through what mechanism that is achieved?I need to call any API/DLL present in my system and change the contents of the main tile.In this case by default the main tile will appear with package.appexmanifest data and then in fractions of seconds the tile contents will change with the current data on main tile.

    Please let me know if there is any way out.

    - Sulekha

  • 2012年7月30日 7:41
    モデレータ
     
     回答済み コードあり

    Hi Sulekha,

    Thanks for the response.

    According to Rob's reply in this case:"Metro style app needs to run in order to set up the live notifications. It can't do this until the user first runs it". So, I do not think you are able to use the TileUpdateManager.CreateTileUpdaterForApplication().Update(tilecontent.CreateNotification()); method to modify the main tile image and text before you start an app.

    You can set up the tile image and contents changes periodically by using TileNotification.ExpirationTime property.

    TileNotification tileNotification = new TileNotification(tileXml);
                Windows.Globalization.Calendar cal = new Windows.Globalization.Calendar();
                cal.SetToNow();
                cal.AddSeconds(10);
                tileNotification.ExpirationTime = cal.GetDateTime();

    And based on your above description, I think that maybe in your scenario you have more than one tiles, and you want to change them automatically. If so, you need first to enable the notification queue for your app. See: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868234.aspx And here is a sample code:

     XmlDocument tileXML_1 = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideImageAndText01);
                XmlNodeList tileTextAttribute = tileXML_1.GetElementsByTagName("text");
                tileTextAttribute[0].AppendChild(tileXML_1.CreateTextNode("This tile notification uses ms-resource images"));
                XmlNodeList tileImageAttributes = tileXML_1.GetElementsByTagName("image");
                ((XmlElement)tileImageAttributes[0]).SetAttribute("src", "ms-resource:TileImages/20110213114606270.jpg");
                XmlDocument tileXML_2 = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideImageAndText01);
                XmlNodeList tileTextAttribute_2 = tileXML_2.GetElementsByTagName("text");
                tileTextAttribute_2[0].AppendChild(tileXML_2.CreateTextNode("This tile notification uses ms-resource images------2"));
                
                XmlNodeList tileImageAttributes_2 = tileXML_2.GetElementsByTagName("image");
                ((XmlElement)tileImageAttributes_2[0]).SetAttribute("src", "ms-resource:TileImages/1_110706120126_5.jpg");
                NotificationSetting setting = TileUpdateManager.CreateTileUpdaterForApplication().Setting;
                TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true);
                TileNotification tileNotification = new TileNotification(tileXML_1);
                tileNotification.Tag = "Wide Tile 1";
                TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);
                TileNotification tileNotification_2 = new TileNotification(tileXML_2);
                tileNotification.Tag = "Wide Tile 2";
                TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification_2);

    Thanks.


    Vicky Song [MSFT]
    MSDN Community Support | Feedback to us