开发者

Live tiles not picking up image from isolated storage

Within my WP7 app, I am generating an image for a live tile and saving in Isolated storage. It is then available for my periodic task to update the live tile with and everything is working fine in this regard for the periodic task.

The problem I have is at the point in my foreground WP7 app when I create the live tile image I also update the live tile (since I know something has changed so why wait for the periodic task). But when the live tile update occurs here, it seems that it cannot find the newly created file and so presents the live tile without the bitmap.

In terms of the relevant code

Creating the file

var source = new BitmapImage(new Uri("Images/Tiles/Class Timetable with T.png", UriKind.Relative));
source.CreateOptions = BitmapCreateOptions.None;
source.ImageOpened += (sender, e) => // This is important. The image can't be rendered before it's开发者_运维技巧 loaded.
{
    // Create our image as a control, so it can be rendered to the WriteableBitmap.
    var newImage = new Image();
    newImage.Source = source;
    newImage.Width = 173;
    newImage.Height = 173;

    // Define the filename for our tile. Take note that a tile image *must* be saved in /Shared/ShellContent
    // or otherwise it won't display.
    var tileImage = string.Format("/Shared/ShellContent/{0}.jpg", Event.UniqueId);

    // Define the path to the isolatedstorage, so we can load our generated tile from there.
    var isoStoreTileImage = string.Format("isostore:{0}", tileImage);

and the actual save itself

// Create a stream to store our file in.
var stream = store.CreateFile(tileImage);

// Invalidate the bitmap to make it actually render.
bitmap.Invalidate();

// Save it to our stream.
bitmap.SaveJpeg(stream, 173, 173, 0, 100);

// Close the stream, and by that saving the file to the ISF.
stream.Close();

and the code that actually retrieves the image and updates the live tile (and works in the periodic task but not from the app itself

string imageString = "isostore:/Shared/ShellContent/" + nextEvent.UniqueId + ".jpg";
ShellTile defaultTile2 = ShellTile.ActiveTiles.First();
defaultTile2.Update(new StandardTileData
{
    Title = nextTime,
    BackgroundImage = (new Uri(imageString, UriKind.Absolute)),

});

Just unsure as to if I am doing something fundamentally wrong here? I am considering storing the generated image in the database with its object. And, I do have a manageable number of files involved here. I am not generating hundreds of the things.

I do have a workaround which is to update the livetile from within the WP7 app without using the image file.


Hey that code looks familiar ;-) That aside, there's nothing in the code you posted that actually can determine the problem.

My guess is that you're calling NotifyComplete() to early in your periodic task. For this, I recommend you use the Task Parallel Library to workaround the problem.

I actually wrote a article about it this very morning: How To: Live Tile with Scheduled Agent

The essential part is to use Task.ContinueWith to ensure that NotifyComplete() is first called after you finished rendering the background image, and saved it to the isolated storage.


You shouldn't need the isostore: prefix on teh path when creating it within the main app. Try just creating a Relative URI to the file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜