Click here to Skip to main content
15,845,681 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Hi all,

I have a "Storyboard" in window resources in XAML of WPF and I want change it (value="375") dynamically in code C# and at run-time.
I also used "Binding, StaticResource and DynamicResource", but it is an error.
You can test it yourself and please help me so about this.

    <storyboard x:key="myStoryboard" xmlns:x="#unknown">
        <doubleanimationusingkeyframes storyboard.targetproperty="(FrameworkElement.Width)" storyboard.targetname="viewbox">
            <easingdoublekeyframe keytime="0:0:1.5">Value="375">
                    <exponentialease easingmode="EaseIn" exponent="10" />

Thanks in advance.
Updated 28-Oct-11 13:49pm

Adjust KeyFrame.Value and restart the Animation or Storyboard.

Storyboard storyboard = Storyboard;
FrameworkElement frameworkElement = Ellipse;

// Restart

That worked fine for me!
Share this answer
Here's one way to get there using code:

EasingDoubleKeyFrame keyFrame = ((this.Resources["myStoryboard"]
    as Storyboard).Children[0]
    as DoubleAnimationUsingKeyFrames).KeyFrames[0]
    as EasingDoubleKeyFrame;

keyFrame.Value = 100.5;

That said, you should be binding it to a property in the view-model and then changing that.
Share this answer
hzawary 28-Oct-11 19:50pm    
My 5, Very good!

I don't understand,may more explain "That said, you should be binding it to a property in the view-model and then changing that." Is this other way?
Nish Nishant 28-Oct-11 20:10pm    
What I meant is that it's better to rely on data binding here. Because here I've made several assumptions about the Xaml. If you ever change the Xaml in future that code will break. But if you bind to a proeprty then it will continue to work.
hzawary 28-Oct-11 20:45pm    
Ok! May tell me that How is it done in this case?
setafonnix 16-Jan-14 11:05am    
This is Solve my problem !, it's can help me to make easing with dynamic values
in winRT, i'm just change...
this.Resources["myStoryboard"] TO mySoryboard.Storyboard.Children[0]
by the way, thanks a lot.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900