Windows Phone 8 secondary tiles crash when not in Debug Mode

238 Views Asked by At

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

1

There are 1 best solutions below

3
Chris Shao On

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 
}