Windows Phone(7/8)上的自定义实时磁贴渲染问题 [英] Custom live tile rendering issue on Windows Phone (7/8)

查看:87
本文介绍了Windows Phone(7/8)上的自定义实时磁贴渲染问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows Phone应用程序的主页上,用户可以单击一个按钮来做一些事情,这将触发实时磁贴更新.

In my Windows Phone app's main page, users can click a button to do some stuff and that will trigger the live tile to update.

我遇到的问题是,如果用户单击该按钮,然后非常快地按下电话的后退"按钮,则实时拼贴有时将无法正确渲染.这个问题很少发生,但是确实会发生,当它发生时看起来就很糟糕...

The problem I am having is, if the user clicks the button and then hit the phone's Back button really quickly, the live tile sometimes will not render properly. This issue rarely happens, but it does happen and when it happens it just looks bad...

我实现实时磁贴的方法是,创建一个看起来与实时磁贴完全相同的用户控件,然后将其保存到隔离存储中.然后检索它并将其存储在FliptileData对象中.最后,我在ShellTile上调用Update方法.请参见下面的代码来演示该过程.

The way I implement the live tile is, create a user control that looks exactly the same as the live tile and then save it to isolated storage. Then retrieve it and store it in a FliptileData object. Finally I call the Update method on the ShellTile. Please see the following piece of code to demonstrate the process.

    // 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"));

我认为造成这种情况的原因是,当用户过快地单击后退"按钮时,操作系统终止了该应用程序中运行的所有进程,并且当时未完成渲染.我在想是否有办法知道渲染何时完成,因此我可以取消后退"按钮并等待直到完成,然后手动退出该应用程序.但是我根本不知道如何...

I think the reason that's causing all this is, when the user clicks the Back button too quickly, the OS terminates all the processes running within the app and the rendering wasn't done at that time. I'm thinking if there's a way to know when the rendering is finished, so I can cancel the Back button and wait until it's finished then manually exit the app. But I simply dunno how...

在此方面的任何帮助将不胜感激!

Any help on this one will be greatly appreciated!

推荐答案

我在WP8应用程序中遇到了类似的问题.问题是我正在ApplicationDeactivated事件处理程序中更新我的Tile.问题是您不应该在那里更新磁贴,而应该在MainPage.OnNavigatedFrom覆盖中更新.一旦我更改了它,它就可以正常工作.

I have ran into similar issue in my WP8 app. The problem was that I was updating my Tile in ApplicationDeactivated event handler. The thing is you should not update your tiles there, but rather in your MainPage.OnNavigatedFrom override. Once I changed this, it works just fine.

这篇关于Windows Phone(7/8)上的自定义实时磁贴渲染问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆