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.
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.
Related
My situation is something like this:
I have a class called MediaElementPlayer which represents a video player, and acts as a ViewModel for a DataTemplate. It is based on this idea with adjustments to WPF and MVVM light instead of Silverlight.
It works great, but I need to be able to maximize the video too.
For that I created a different window called FullScreenWindow, which holds a single ItemContainer to draw the video player. When I create this window, I pass it the MediaElementPlayer object from the main window. This works too.
The problem is that when the full screen window is opened, the media's position is not retained, that's because it creates a new MediaElement.
Is there a way I can take the MediaElement object I already have in mt MediaElementPlayer(VM) and draw it on the view, instead of creating a new one? That will help me retain media position across windows.
Thank you very much in advance.
You can create a new MediaElement UserControl in your FullScreenWindow then use Binding to set its size: you can bind the MediaElement object actual Size to a property of the ViewModel MediaElementPlayer (you can update these values by creating a behaviour attached to SizeChanged event of the UserControl).
Then, the ViewModel of the FullScreenWindow can set the Size of the its MediaElement basing on the property of the ViewModel.
I am completely new to wpf and the question is this.
Is there available xaml for the control like on attached image?
As you can see, when we click on a control the image on the left becomes larger and all the text slides to the left. Or how could I create similar control?
The easiest way to accomplish that is a Storyboard.
Open Expression-Blend, build a Control. Hide all Elements you dont see first so its small. Create a new Storyboard, make a Keyframe and change the Properties of the elements you then want to change, create a new Keyframe.
Its like an Animation now. You can now start the Storyboard any time, on any event to expand your control.
If you dont know how to use Expression Blend and the Storyboard, there are some fine Tutorials and Videos.
Good luck!
In Silverlight for Windows phone, I need to go to a specific place in a page by code (hopefully with animation). The requirement is a bit like navigate to a specific anchor in HTML using url such as http://url#anchorname. However, I don't know how to do it in Windows Phone. Any ideas?
What do you mean by "go"? You could try setting the focus on a control calling control.Focus(). If you want to just scroll a ScrollViewer or a ListBox to display a control that is inside of it - WPF had a BringIntoView() method that some people ported to Silverlight, eg. here.
If you want animation - you will need to add an attached dependency property that will allow to run an animation updating the scroll offset using ScrollToVerticalOffset(). Then have the BringIntoView implementation - instead of just jumping to the offset using ScrollToVerticalOffset - run an animation that will update the attached dependency property and smoothly animate calling ScrollToVerticalOffset many times.
I've got a custom composite WPF control (AvalonEdit) in my application that I'd like to animate whenever its Text property is changed. What I intend to do is:
Create a copy of the control's visual representation before the text is changed and paint it over a rectangle.
Fade out the above rectangle, update the text property and fade in the control using the DoubleAnimation and Storyboard classes.
I've got #2 figured out but haven't got a clue about how I'd achieve #1. Any help would be appreciated.
For (1) there are a couple of approaches that spring to mind:
VisualBrush - A visual brush is a brush which is defined by a complex UI element. In other words, you can create a visual tree of elements and use this to create your brush. See the tutorial here. I think in your case you would have to define your UI twice, i.e. have an instance of your AvalonEdit control as the 'visual' for you VisualBrush, so perhaps not ideal
WriteableBitmap - A writeable bitmap allows you to copy part of your UI into a bitmap where you can manipulate he pixel data. Whilst you do not need pixel-level manipulation it is still a convenient mechanism for cloning your UI. See this tutorial I wrote here.
I was wondering the need for custom xaml code for buttons.
Using images like in html should be faster.
Yours thoughts please.
The whole point of WPF is that it is independent of pixel resolution or DPI. If you use raster images for the buttons it is no longer DPI independent and can look bad on some resolutions. If, instead, you use WPF objects and geometries, those will look almost exactly the same on any DPI.
What happens when you want to change something small to do with the button? Using custom XAML allows me to apply the same template to all my buttons, and change them all by just changing that template. It also means that I can tweak small things without the need to constantly regenerate those images.
As for speed, you're best off not pre-empting the framework's optimisations until you actually encounter a performance issue.
EDIT: I should also note that the Image class doesn't inherit from Button, and as such you can't do the direct binding to an ICommand property in the ViewModel.