IT tutorials
 
Technology
 

Windows Phone 8 : Phone Integration - Live Tiles (part 2)

8/13/2013 11:16:53 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Main Live Tile

Your application has a single main Live Tile that is added to the home screen when a user manually pins your application. You can get at this Live Tile (whether it has been pinned or not) by accessing the ShellTile.ActiveTiles property. This property returns an enumerable list of the tiles in your application:

IEnumerable<ShellTile> tiles = ShellTile.ActiveTiles;

// Get the default tile
var tile = tiles.First();

The ShellTile class represents a tile for the home screen. The Active-Tiles property is a collection of these ShellTile objects. The first one is always the default tile. This class allows you to update the default tile. To update the default tile, you can create a data structure that matches the style of live tile you want. For instance, to create a Flip style, you would use a class called FlipTileData that contains the data with which to update the tile:

IEnumerable<ShellTile> tiles = ShellTile.ActiveTiles;

// Get the default tile
var tile = tiles.First();

// The new tile information to use to update the tile
var tileData = new FlipTileData()
{
  Title = "Live Tile Updated!",
  Count = 54,
  BackgroundImage =
    new Uri("/Assets/Tiles/icon-336.png", UriKind.Relative),
  SmallBackgroundImage =
    new Uri("/Assets/Tiles/icon-159.png", UriKind.Relative),
  WideBackgroundImage =
   new Uri("/Assets/Tiles/icon-wide.png", UriKind.Relative),
};

// Update the Tile
tile.Update(tileData);

Calling the Update method will update the tile with the new information. If the default tile (in this case) has not been pinned yet, when the application is pinned it will include this new set of information instead of the information contained in the WMAppManifest.xml file.

The Flip style of icon supports both the front (which we set previously) and a set of properties for the back of the live tile. To set these, just set the rest of the properties like so:

var tileData = new FlipTileData()
{
  Title = "Live Tile Updated!",
  Count = 54,
  BackgroundImage =
    new Uri("/Assets/Tiles/icon-336.png", UriKind.Relative),
  SmallBackgroundImage =
    new Uri("/Assets/Tiles/icon-159.png", UriKind.Relative),
  WideBackgroundImage =
    new Uri("/Assets/Tiles/icon-wide.png", UriKind.Relative),
  BackTitle = "Live Tiles",
  BackContent = "This is standard content",
  WideBackContent = "This is even more content!"
};

These properties are used to specify what is on the back of the tile. You can also specify a background image if you don’t want to simply use the theme color as a background.

Be careful selecting the style of live tile in your WMAppManifest.xml file because you can’t change the style of your main live tile. This means when you update the main live tile, you have to use the correct StandardData derived class to update it (for example, FlipTileData, CycleTileData, and IconicTileData).

Secondary Tiles

You can also create all-new tiles that are pinned to the home screen for the user. The purpose of these secondary tiles is to open deeper parts of your application. For example, imagine you have an application that shows the user RSS feeds. You might create a Live Tile that goes to a specific RSS feed instead of the default view that a new launching of the application would go to. This enables you to deep-link into your application. To do this, you use the same StandardTileData derived classes that were used to update the main live tile, but in this case you can create a new tile using the ShellTile.Create method:

var tileData = new IconicTileData()
{
  IconImage =
    new Uri("/Assets/Tiles/icon-202.png", UriKind.Relative),
  SmallIconImage =
    new Uri("/Assets/Tiles/icon-101.png", UriKind.Relative),
  Count = 5,
  WideContent1 = "This is line 1",
  WideContent2 = "This is line 2",
  WideContent3 = "This is line 3"
};

var deepUri = new Uri("/DeepLinkPage.xaml?id=Hello World",
                      UriKind.Relative);

ShellTile.Create(deepUri, tileData, true);

You should notice that the ShellTile.Create method requires a URI to be specified. This URI is used as the location from which to launch the navigation in your application. This is how deep-linking works. You can see in this example the URI is going to a view we have called DeepLinkPage.xaml and I am passing in a query string to help that view know how to show the data the Live Tile is specifying. This URI must be unique for all secondary tiles, so if you try to create a new secondary tile with the same URI, it will throw an exception. In addition, the last parameter is required (there is an overload without the third parameter, but it’s there only for backward-compatibility). This last parameter specifies whether the tile supports a wide tile.

When ShellTile.Create is called, it takes the user to the home screen and scrolls to the new tile (to allow the user to move it on the home screen if she desires). This behavior is not overrideable. The purpose of going to the home screen is to prevent applications from hiding from the user the fact that they are adding new tiles. Because it deactivates the application, if the user did not want the Live Tile added, he could just delete it and not launch the nefarious application again.

You can find your own Live Tiles by interrogating the NavigationUri property of the ShellTile class (in the ActiveTile collection), like so:

var myTile = ShellTile.ActiveTiles
                      .Where(t => t.NavigationUri
                                   .OriginalString
                                   .Contains("DeepLinkPage.xaml"))
                      .FirstOrDefault();

// If it was found
if (myTile != null)
{
  // ...
}

After you find the appropriate tile, you can update it like you did the default tile:

  // If it was found
if (myTile != null)
{
  var tileData = new IconicTileData()
  {
    IconImage =
      new Uri("/Assets/Tiles/icon-202.png", UriKind.Relative),
    SmallIconImage =
      new Uri("/Assets/Tiles/icon-101.png", UriKind.Relative),
    Count = 15,
    WideContent1 = "It was updated!",
    WideContent2 = "This is line 2",
    WideContent3 = "This is line 3"
  };

  myTile.Update(tileData);
}

Typically you should change the tile with some information for the user to see that she should revisit your application (like updating the Count property).

If you need to change something else (like the NavigationUri), you need to delete the tile and re-create it. The ShellTile class allows you to delete a Live Tile (as long as it is not the default tile):

myTile.Delete();

On the whole, secondary tiles can be a very powerful feature, but the user will not necessarily tolerate a lot of tiles from a single application, so using this functionality judiciously is encouraged!

 
Others
 
- Windows Phone 8 : Phone Integration - Live Tiles (part 1)
- Active Directory 2008 : Administering Groups in an Enterprise (part 3) - Understanding Shadow Groups, Default Groups
- Active Directory 2008 : Administering Groups in an Enterprise (part 2) - Delegating the Management of Group Membership
- Active Directory 2008 : Administering Groups in an Enterprise (part 1) - Protecting Groups from Accidental Deletion
- Active Directory 2008 : Automating the Creation and Management of Groups (part 2)
- Active Directory 2008 : Automating the Creation and Management of Groups (part 1)
- Managing Exchange Server 2010 Features for Mobile Devices (part 8) - Understanding and Using WebReady Document Viewing
- Managing Exchange Server 2010 Features for Mobile Devices (part 7) - Understanding and Configuring Remote File Access
- Managing Exchange Server 2010 Features for Mobile Devices (part 6) - Understanding and Configuring Direct File Access
- Managing Exchange Server 2010 Features for Mobile Devices (part 5) - Understanding and Using Remote Device Wipe
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us