Jus*_* XL 5 windows-phone-7 windows-phone-7.1 live-tile windows-phone-8
在我的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"));
Run Code Online (Sandbox Code Playgroud)
我认为造成这一切的原因是,当用户太快地单击"后退"按钮时,操作系统会终止应用程序中运行的所有进程,并且当时没有完成呈现.我在想是否有办法知道渲染何时完成,所以我可以取消后退按钮并等到它完成然后手动退出应用程序.但我简直不知道如何......
任何有关这一方面的帮助将不胜感激!
我在WP8应用程序中遇到了类似的问题.问题是我在ApplicationDeactivated事件处理程序中更新了我的Tile.问题是你不应该更新你的瓷砖,而是更新你的MainPage.OnNavigatedFrom覆盖.一旦我改变了它,它就可以了.
| 归档时间: |
|
| 查看次数: |
1658 次 |
| 最近记录: |