Skip to main content

Microsoft Silverlight

Answered Question Start Animation from ViewModelRSS Feed

(0)

neal.gabriel
neal.gab...

Participant

Participant

789 points

161 Posts

Start Animation from ViewModel

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;

Regards...

Neal Gabriel

Sergey.Lutay
Sergey.L...

Contributor

Contributor

7198 points

1,340 Posts

Re: Start Animation from ViewModel

Hi,

Why you can't define an event which will notify your view about modification of property?

(If this has answered your question, please click on "mark as answer" on this post. Thank you!)

Blog

Twitter

Sincerely,
Sergey Lutay

neal.gabriel
neal.gab...

Participant

Participant

789 points

161 Posts

Re: Re: Start Animation from ViewModel

 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.. :)

 

Regards...

Neal Gabriel

Sergey.Lutay
Sergey.L...

Contributor

Contributor

7198 points

1,340 Posts

Re: Re: Start Animation from ViewModel

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

(If this has answered your question, please click on "mark as answer" on this post. Thank you!)

Blog

Twitter

Sincerely,
Sergey Lutay

neal.gabriel
neal.gab...

Participant

Participant

789 points

161 Posts

Re: Re: Re: Start Animation from ViewModel

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,

 

Regards...

Neal Gabriel

Sergey.Lutay
Sergey.L...

Contributor

Contributor

7198 points

1,340 Posts

Re: Re: Re: Start Animation from ViewModel

Can you show a code where that exception is arise?

(If this has answered your question, please click on "mark as answer" on this post. Thank you!)

Blog

Twitter

Sincerely,
Sergey Lutay

neal.gabriel
neal.gab...

Participant

Participant

789 points

161 Posts

Re: Re: Re: Re: Start Animation from ViewModel

Silverlight Error - For Triggers As I said, This wont work with Silverlight (I m using SL 3);

Regards...

Neal Gabriel

Sergey.Lutay
Sergey.L...

Contributor

Contributor

7198 points

1,340 Posts

Re: Re: Re: Re: Start Animation from ViewModel

Have you tried to start animation from code behind?

(If this has answered your question, please click on "mark as answer" on this post. Thank you!)

Blog

Twitter

Sincerely,
Sergey Lutay

neal.gabriel
neal.gab...

Participant

Participant

789 points

161 Posts

Re: Re: Re: Re: Re: Start Animation from ViewModel

Yes, and it will work, But What I want is a Complete MVVM Pattern Applicaton that can start Animation (Begin Storyboard) from the ViewModel

Regards...

Neal Gabriel

neal.gabriel
neal.gab...

Participant

Participant

789 points

161 Posts

Answered Question

Re: Re: Re: Re: Re: Re: Start Animation from ViewModel

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

Regards...

Neal Gabriel

plogic
plogic

Member

Member

72 points

12 Posts

Re: Re: Re: Re: Start Animation from ViewModel

  from the SL3 docs:
                EventTrigger can only support a triggering action for the Loaded event
                so your attempt <EventTrigger RoutedEvent="ImageOpened"> is no good

plogic
plogic

Member

Member

72 points

12 Posts

Re: Re: Re: Re: Start Animation from ViewModel

 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

neal.gabriel
neal.gab...

Participant

Participant

789 points

161 Posts

Re: Re: Re: Re: Re: Start Animation from ViewModel

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

 

Regards...

Neal Gabriel

plogic
plogic

Member

Member

72 points

12 Posts

Re: Re: Re: Re: Re: Start Animation from ViewModel

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

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities