Assign WritableBitmap to an ImageBrush.ImageSource property
I want to have an animated panorama control background in Windows Phone application.
I have an algorithm that constantly draws onto the WritableBitmap the desired image.
I have bound the Panoramas' background property to ViewModels' BackgroundImageBrush property.
Then at construction time of my ViewModel I assign
BackgroundImageBrush = new ImageBrush {ImageSource = _outputWriteableBitmap};
I get no Binding errors in output and wh开发者_Go百科en I check the binding at with the debugger, I get the correct linkage of BackgroundImageBrush.ImageSource to a WritableBitmap.
Every time I redraw the _outputWriteableBitmap I do call Invalidate.
Still my panorama background is blank!
What am I doing wrong in theory? Is it even possible to have an animated background in Windows Phone's Panorama?
Thanks.
The first step here is to make sure that the binding is actually working. Try creating a static image brush and binding your panorama background to that. If that works, then the issue is with the way you're updating the image--either the image isn't rendering properly or you're not calling PropertyChanged
correctly.
I've bound a panorama background image to a property in a viewmodel before, so it is doable.
Incidentally, how often will you be updating this image? It could be brutal on your performance if it happens frequently.
A way offered in the comments below the question has the potential answer.
This blog post shows how to at least change the panorama background at runtime, tough I didn't manage get it to play animation generated at runtime.
精彩评论