在我的Windows Phone应用程序的主页中,用户可以点击一个按钮来做一些事情,这将触发活动磁贴更新。
我遇到的问题是,如果用户点击按钮,然后非常快地点击手机的后退按钮,活动磁贴有时不会正确渲染。这种问题很少发生,但它确实发生了,当它发生时,它看起来很糟糕……

我实现活动磁贴的方法是,创建一个看起来与活动磁贴完全相同的用户控件,然后将其保存到独立存储中。然后检索它并将其存储在FliptileData对象中。最后,我在ShellTile上调用了Update方法。请看下面的代码来演示这个过程。
// the function that saves the user control to isolated storage
public Uri SaveJpegToIsolatedStorage(FrameworkElement tile, string suffix, int tileWidth = 336, int tileHeight = 336)
{
var bmp = new WriteableBitmap(tileWidth, tileHeight);
// Force the content to layout itself properly
tile.Measure(new Size(tileWidth, tileHeight));
tile.Arrange(new Rect(0, 0, tileWidth, tileHeight));
bmp.Render(tile, null);
bmp.Invalidate();
// Obtain the virtual store for the application
IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication();
using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(IsolatedStorageFileName + suffix, FileMode.Create, myStore))
{
try
{
bmp.SaveJpeg(fileStream, tileWidth, tileHeight, 0, 100);
}
catch (Exception)
{
return null;
}
}
return new Uri("isostore:/" + IsolatedStorageFileName + suffix, UriKind.Absolute);
}
// save the user control to isolated storage and prepare the FlipTileData object
wideFrontTileImage = SaveJpegToIsolatedStorage((UserControl)this.WideFrontTile, "_wide_front", 691);
var flipTileData = new FlipTileData();
flipTileData.WideBackgroundImage = wideFrontTileImage;
return flipTileData;
// update the live tile
var shellTile = ShellTile.ActiveTiles.FirstOrDefault();
shellTile.Update(customTile.GetFlipTileData(data.UndoneMemosCount == "0" && data.TotalMemosCount == "0"));我认为导致这一切的原因是,当用户单击后退按钮太快时,操作系统会终止在应用程序中运行的所有进程,并且当时没有完成渲染。我在想,是否有办法知道渲染何时完成,这样我就可以取消后退按钮,等待渲染完成,然后手动退出应用程序。但我就是不知道怎么.
在这个问题上的任何帮助都将非常感谢!
发布于 2013-01-09 16:41:09
我在我的WP8应用中也遇到过类似的问题。问题是我正在更新我的Tile in ApplicationDeactivated事件处理程序。问题是你不应该在那里更新你的磁贴,而应该在你的MainPage.OnNavigatedFrom覆盖中更新。一旦我改变了这一点,它就能正常工作。
https://stackoverflow.com/questions/14229966
复制相似问题