I have an ellipse like this:
<Ellipse Width="40" Height="50" Fill="Green">
<Ellipse.RenderTransform>
<RotateTransform Angle="0" CenterX="20" CenterY="25" />
</Ellipse.RenderTransform>
<Ellipse.Triggers>
<EventTrigger RoutedEvent="Ellipse.Loaded" >
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.Angle"
From="0" To="360" Duration="{Binding Path=Dudu}" RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Ellipse.Triggers>
</Ellipse>
I want the ellipse rotate with speed depend on the Dudu
property (this property use INotifyPropertyChanged
to notify changed).
But duration is not changed when I change value of Dudu
. I figured out the problem is Loaded
event just raise on first time control is loaded only.
My question is: How can I change duration by change value of a property? What event should I use?
I think the problem could be with the bonded property
Dudu
itself. see if it is been properly resolved and is of correct typeI attempted to create an alternative solution if above does not work
here is a sample using attached behavior
note that I have removed the trigger with the storyboard and attached the property
AnimationHelper.AnimationDuration="0:0:2"
you may bind it asAnimationHelper.AnimationDuration="{Binding Path=Dudu}"
AnimationHelper class
also note that above example uses a hard-coded DoubleAnimation on the RenderTransform property. Assuming that RenderTransform is initialized with an instance of RotateTransform. you may also extend the behavior make it dynamic if needed.