If you place the following code in the game loop (Update or Draw) of a MonoGame app (can just be the default project template):
new Windows.UI.Xaml.Media.Imaging.WriteableBitmap(150, 150);
It throws a cross-thread error…
The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))
So then I tried this:
var dispatcher = Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher;
dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, delegate
{
new Windows.UI.Xaml.Media.Imaging.WriteableBitmap(150, 150);
});
Same error.
Looking under the covers, it doesn’t look like MonoGame runs the game loop on a background thread or anything. It uses a synchronous loop.
Any ideas of a way to use WriteableBitmap in MonoGame? (I need to use it to render out some live tiles)
If you’re using the Game class then your creating an application that by default does not support XAML.
Currently the best way to support XAML in a MonoGame app is to use the Siverlight-style XNA game as outlined in this thread…
http://monogame.codeplex.com/discussions/359544