Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# XAML WPF
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.
 
    <window.resources>
        <storyboard x:key="myStoryboard" xmlns:x="#unknown">
            <doubleanimationusingkeyframes storyboard.targetproperty="(FrameworkElement.Width)" storyboard.targetname="viewbox">
                <easingdoublekeyframe keytime="0:0:1.5">Value="375">
                    <easingdoublekeyframe.easingfunction>
                        <exponentialease easingmode="EaseIn" exponent="10" />
                    </easingdoublekeyframe.easingfunction>
                </easingdoublekeyframe>
            </doubleanimationusingkeyframes>
        </storyboard>
    </window.resources>
 
Thanks in advance.
Posted 28-Oct-11 13:44pm
hzawary1.5K
Edited 28-Oct-11 13:49pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
hzawary at 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?
Nishant Sivakumar at 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 at 28-Oct-11 20:45pm
   
Ok! May tell me that How is it done in this case?
setafonnix at 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)



Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 28 Oct 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100