简体   繁体   中英

Windows Phone 8 secondary tiles crash when not in Debug Mode

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

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 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM