Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Start Animation from ViewModel
13 replies. Latest Post by plogic on September 24, 2009.
(0)
neal.gab...
Participant
789 points
161 Posts
09-18-2009 7:36 AM |
Is it possible to start an animation (StoryBoard in the XAML) from ViewModel ?or
Is there any other way to Start the StoryBoard in the XAML itself, if So, How ? [I dont want it in EventTriggers = "Loaded"]or
Is there any way to Build a storyboard and launch it from the viewModel ?
My Objective is to follow the MVVM Pattern and begin the storyboard; The Storyboard will begin based on an Button Click Event (we can get the event in viewModel, Here what I have used is ICommand) from another form. On Click event, one of the property in the viewmodel changes; According to the property, I need to start an animation;
Sergey.L...
Contributor
7198 points
1,340 Posts
09-18-2009 6:02 PM |
Hi,
Why you can't define an event which will notify your view about modification of property?
09-19-2009 9:30 AM |
Hi Sergey,
Thank you for the quick reply.
Like I said I have a property and based and property notification is getting triggered.. But What I want is to Start StoryBoard on this PropertyChange.
i.e Say StoryBoard name is FadeIn, then FadeIn.Begin() should happen in propertychange ? Does my question seems confusing ? I can post some code, if it is.. :)
09-20-2009 9:13 AM |
Maybe information for SDK will help you:
....
For animating properties on objects that are not controls, place the storyboard in the general Resources for a page or application. Then assign an event handler on the element where you would have placed "Triggers". The event handler, when responding to the relevant event, should retrieve the storyboard from the resource dictionary. You then call Begin on the retrieved Storyboard.
Source http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.triggers(VS.95).aspx
09-20-2009 11:48 AM |
This wont work; Like I already mentioned in the beginning of this topic,:(
Error is Attribute ImageOpened value is out of range. [Line: 33 Position: 47]
What I have tried is as follows
<Image x:Name="MenuControlImage" Source="{Binding ImageUrl, Converter={StaticResource ImageConverter}}"> <Image.Triggers> <EventTrigger RoutedEvent="ImageOpened"> <BeginStoryboard> <Storyboard x:Name="MyStoryboard"> <DoubleAnimation Duration="00:00:00.500" From="0.00" To="1.00" Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="Opacity" /> </Storyboard> </BeginStoryboard> </EventTrigger> </Image.Triggers> </Image>
What I will need is something like a Converter that begins the Storyboard,
09-20-2009 2:12 PM |
Can you show a code where that exception is arise?
09-20-2009 11:51 PM |
As I said, This wont work with Silverlight (I m using SL 3);
09-21-2009 1:51 AM |
Have you tried to start animation from code behind?
09-21-2009 2:11 AM |
Yes, and it will work, But What I want is a Complete MVVM Pattern Applicaton that can start Animation (Begin Storyboard) from the ViewModel
09-21-2009 2:40 AM |
Hey Sergey,
Thank you very much for the Help; At last I found a solution for the problem
http://chris.59north.com/post/mvvm-and-animations.aspx
plogic
Member
72 points
12 Posts
09-22-2009 7:21 PM |
from the SL3 docs: EventTrigger can only support a triggering action for the Loaded event so your attempt <EventTrigger RoutedEvent="ImageOpened"> is no good
09-23-2009 5:38 PM |
I looked around for other solutions and found a few. Its too long for this forum but you can read the blog post here: http://blog.flexforcefive.com/?p=206
09-24-2009 12:10 PM |
Thank you for the reply,
The method you have provided is same as that of the solution I have found in http://chris.59north.com/post/mvvm-and-animations.aspx
09-24-2009 6:26 PM |
Correct, same as you found, as indicated in the blog post. In addition there are other alternatives to Chris North's cited that others considering alternatives may want to consider..