我正在尝试在 Windows Phone 8 中使用 FlipTileData 创建一个磁贴。我使用以下代码:
const string mainPage = "/MainPage.xaml";
...
Uri mp = new Uri(mainPage + "?" + "tileid=" + tileId, UriKind.Relative);
FlipTileData tileData = new FlipTileData();
tileData.Title = tileTitle;
tileData.BackgroundImage = new Uri("isostore:" + isourl);
tileData.SmallBackgroundImage = new Uri("isostore:" + isourl);
tileData.WideBackgroundImage = new Uri("isostore:" + isourl);
ShellTile.Create(mp, tileData);
这会在 ShellTile.Create 方法中引发 InvalidOperationException。没有其他磁贴具有相同的导航 URI。我在这里做错了什么?
此代码使用 StandardTileData 类可以正常工作,不包括 SmallBackgroundImage 和 WideBackgroundImage 属性。
如果重要的话,完整的代码是:
const string mainPage = "/MainPage.xaml";
...
private void createbutton_Click(object sender, RoutedEventArgs e)
{
string tileId = new Random().Next().ToString();
Uri mp = new Uri(mainPage + "?" + "tileid=" + tileId, UriKind.Relative);
WriteableBitmap wbmp = new WriteableBitmap(tileGrid, null);
string isourl = "/Shared/ShellContent/" + tileId + ".jpg";
IsolatedStorageFileStream isfs = IsolatedStorageFile.GetUserStoreForApplication().CreateFile(isourl);
wbmp.SaveJpeg(isfs, 173, 173, 0, 100);
isfs.Close();
FlipTileData tileData = new FlipTileData();
tileData.Title = tileTitle;
tileData.BackgroundImage = new Uri("isostore:" + isourl);
tileData.SmallBackgroundImage = new Uri("isostore:" + isourl);
tileData.WideBackgroundImage = new Uri("isostore:" + isourl);
ShellTile.Create(mp, tileData);
}