1

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 when 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.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Maxim V. Pavlov
  • 10,303
  • 17
  • 74
  • 174
  • Are you firing the `PropertyChanged` event for `BackgroundImageBrush` so your UI knows that it's changed? – ChrisF Jun 10 '11 at 10:21
  • Yes I do. But it only happens when I link the WritableBitmap to an ImageSource property of the ImageBrush. – Maxim V. Pavlov Jun 10 '11 at 12:54
  • 1
    Have a look at Jeff Wilcox's implemenation of the fading animation. It might be useful: http://www.jeff.wilcox.name/2010/11/wp7-panorama-smooth-background-changing/ – keyboardP Jun 10 '11 at 15:13

2 Answers2

0

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.

Josh Earl
  • 18,151
  • 15
  • 62
  • 91
  • It's a live animation, so the update should take place every 33 milliseconds. I do call the PropertyChanged to inform the UI about an update, however I only do it when linking the WritableBitmap to an ImageSource property of the brush, not every time I call .Invalidate() on a WritableBitmap. – Maxim V. Pavlov Jun 10 '11 at 12:53
  • `PropertyChanged` is probably only get called once, when everything loads. I would think the image would display initially, though, and just not update properly. I am still suspicious of the binding. Refreshing the entire panorama background every 33 milliseconds does sound to me like it will cause a perf issue, but I've never tried it. – Josh Earl Jun 10 '11 at 13:16
  • Here is what I have observed so far: When I initially assign ImageBitmap.ImageSource to BitmapImage (static), I can see the background fine. But when I initially assign it to WritableBitmap, I neither can see the desired background that my app draws, nor I can latter change it to BitmapImage. The assignment simple has no effect, even though I am sure that I notify the UI about the fact, that it should reevaluate ImageBrush. – Maxim V. Pavlov Jun 10 '11 at 15:04
0

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.

Maxim V. Pavlov
  • 10,303
  • 17
  • 74
  • 174