Windows phone 7 Windows Phone上的自定义实时磁贴渲染问题(7/8)
在我的Windows Phone应用程序的主页中,用户可以单击按钮执行一些操作,这将触发live互动程序进行更新 我遇到的问题是,如果用户点击按钮,然后很快点击手机的后退按钮,实时互动程序有时无法正确渲染。这个问题很少发生,但它确实发生了,当它发生的时候,看起来很糟糕 我实现活动磁贴的方法是,创建一个看起来与活动磁贴完全相同的用户控件,然后将其保存到独立存储中。然后检索它并将其存储在FliptileData对象中。最后,我在ShellTile上调用Update方法。请参阅下面的代码来演示该过程Windows phone 7 Windows Phone上的自定义实时磁贴渲染问题(7/8),windows-phone-7,windows-phone-7.1,windows-phone-8,live-tile,Windows Phone 7,Windows Phone 7.1,Windows Phone 8,Live Tile,在我的Windows Phone应用程序的主页中,用户可以单击按钮执行一些操作,这将触发live互动程序进行更新 我遇到的问题是,如果用户点击按钮,然后很快点击手机的后退按钮,实时互动程序有时无法正确渲染。这个问题很少发生,但它确实发生了,当它发生的时候,看起来很糟糕 我实现活动磁贴的方法是,创建一个看起来与活动磁贴完全相同的用户控件,然后将其保存到独立存储中。然后检索它并将其存储在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"));
我认为造成这一切的原因是,当用户太快地单击“后退”按钮时,操作系统会终止应用程序中运行的所有进程,而渲染当时没有完成。我在想,是否有办法知道渲染何时完成,这样我就可以取消“后退”按钮,等待渲染完成,然后手动退出应用程序。但我只是不知道如何
在这方面的任何帮助都将不胜感激 我在WP8应用程序中遇到了类似的问题。问题是我正在更新ApplicationEnabled事件处理程序中的互动程序。问题是你不应该在那里更新你的磁贴,而应该在你的主页上更新。一旦我改变了这个,它就可以正常工作了 实际上,在用户单击按钮之后,我在视图模型中调用update。我不确定它是否能在OnNavigatedFrom中工作。我会试一试让你知道,谢谢!如果您正在更新ViewModel中的互动程序,则无法控制应用程序是否同时关闭,除非您实现某种关闭通知机制。以这种方式更新OnNavigatedFrom应该是安全的。我认为你是对的!然而,我注意到一件事,每次创建usercontrol的新实例时,我都必须调用UpdateLayout以使其正确呈现。你的回答真的帮助我找到了正确的方法。非常感谢!:)+1.这是一个记录在案的WP7->WP8怪癖。“在Windows Phone 8中,在关闭处理程序中使用Create(Uri,ShellTileData)方法创建互动程序将引发InvalidOperationException。”@谢谢@JustinAngel,该链接非常有用!