I have one applications in Windows Phone 8.1 where at run time I generate multiple buttons from ViewModel and populate those into a Canvas, all the buttons are placed in the canvas at dynamic locations. Now after some condition I regenerate different number of buttons and again populate in the Canvas UI. Every time I do it through ViewModel.
Now I want some animations in the Canvas when the game turns from Label 1 to Label 2.
The GamePage.xaml contains a canvas control.
<Canvas Grid.Row="2" x:Name="gameCanvas" >
<ItemsControl ItemsSource="{Binding Path=ButtonItems}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button
Height="{Binding Height}"
Width="{Binding Width}"
Content="{Binding Content}">
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl>
</Canvas>
Is it possible to trigger an animations for the Buttons
which are placed inside a DataTemplate
? If I want to have flip buttons style, say Label 1 Buttons
will flip horizontally and disappear, and Label 2 buttons
will appear flip vertically? Or any Opacity animations.
I want to do this through DataBinding
to some Property in ViewModel
. I know that in Windows Phone 8.1 <Style.Triggers>
is not there. So how can I achieve this? Any help would be greatly appreciated.
Thanks
Note: This solution might not be work with a data-bound list; I haven't tried that. But it works if you can name each item added to your UI (which must be done programmatically). But if animation is more important to you than the data-bound-ness of the items, then this could work.
Assuming you have a fixed number of items to move around, you can almost (but not quite) do it with Visual States. Here is an example that shows you how you can do it trivially for a single
Button
that moves randomly whenever you click it.XAML
Code
You should be able to generalize this to multiple Buttons, and using whatever databinding technique you need. The trick is that you must flip-flop between two visual states, and you can only do that in code. And if you don't have a fixed number of elements, you can generate the Visual States in code as well (but again, not by data binding).