0

I am testing a basic secondary live tile(ShellTile) functionality with the code below. Creating the tile works fine but using the tile to navigate to the URI always works in debug mode but not when testing disconnected from the computer and I don't know why. I am testing with just 1 tile. Funny thing is, if I restart, secondary tile will work one more time after the restart. What am I missing?

1> This is the code behind that makes the secondary tile

    string path = @"/Views/test.xaml?text=" + parameter.ToString();
    StandardTileData tileData = new StandardTileData
    {
    Title = parameter.ToString(),
    BackTitle = parameter.ToString(),
    BackContent = parameter.ToString()
    };

ShellTile.Create(new Uri(path, UriKind.Relative), tileData);

2.test.xaml code

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    string text= "";
    text= NavigationContext.QueryString["text"];
}

Thanks, Jamie

Jamie L.
  • 144
  • 1
  • 10
  • fyi `string text= "";` completely unnecessary. Just use `var text = NavigationContext...` –  Mar 11 '14 at 13:02

1 Answers1

0

When the Tile which NavigationUri is same with your parameter, the ShellTile.Create method will crash. You should check if the tile is exist first, like this:

ShellTile TileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains(parameter));

You can choose Contains or Equals by your content. and then:

if (TileToFind != null)
{
// Tile is existed, you can update it, but not add the same uri tile
}
else
{
// you can add new tile 
}
Chris Shao
  • 8,231
  • 3
  • 39
  • 37
  • Thank you Chris. This is a good point but I was not clear in my question. The crash happens when navigating using the secondary tile and not on tile creation. I am testing the most base of scenarios because I have not made any notable WP apps. :) – Jamie L. Mar 11 '14 at 02:16
  • can you track it to see if the QueryString of 'text' is not existed in test.xaml? – Chris Shao Mar 11 '14 at 02:41
  • This is also a good point. The query string is just as expected when debugging. I appreciate your attention on this. I think that my weakness is my lack of understanding of the resume process in the app.xaml.cs. I am considering deploying to the app store and seeing if loading the app from the store results differently. – Jamie L. Mar 11 '14 at 12:36