I'm attempting to create an image using a xaml control and writable bitmap. I'd say about 95% of the time it works fine while the app is running and have yet to see it fail in the schedule task. When it does fail, the image it creates is odd. All elements align to the top left corner, with a black background (color should be PhoneAccentBrush). I've tried many things to fix this but I'm lost. The only way I can replicate the issue is if I don't call Measure and Arrange. Below is the code, any ideas?
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
TileHelper.UpdateFlipTile(this.LiveTile, this.Facility, this.METARs[0]);
});
public static void UpdateFlipTile(ShellTile shellTile, Facility facility, METAR metar)
{
/*removed some variables to shorten code*/
WriteableBitmap mediumImage = TileHelper.CreateMediumTileImage(facility.Description, metar.flight_category, wind, TileHelper.GetUri(metar), temp, metar.observation_time);
SaveImage(mediumImageFileName, mediumImage);
FlipTileData flipTile = new FlipTileData()
{
Title = "",
BackTitle = "",
BackContent = "",
WideBackContent = "",
BackgroundImage = new Uri("isostore:/Shared/ShellContent/" + siteNumberEncoded + ".jpg", UriKind.Absolute)
};
shellTile.Update(flipTile);
}
}
private static WriteableBitmap CreateMediumTileImage(string airport, string flightCategory, string wind, Uri imageUri, string temp, string lastUpdated)
{
MediumMetarTile tile = new MediumMetarTile(airport.ToLower(), wind, flightCategory, temp, lastUpdated, imageUri);
tile.Measure(new Size(336, 336));
tile.Arrange(new Rect(0, 0, 336, 336));
WriteableBitmap image = new WriteableBitmap(336, 336);
image.Render(tile, null);
image.Invalidate();
System.Diagnostics.Debugger.Log(0, "TileHelper.CreateMediumTileImage", "medium tile image created");
return image;
}