简体   繁体   中英

Animating a databound progressbar in Silverlight declaratively (no code-behind)

How does one animate a ProgressBar whose Value property is databound?

<ProgressBar Height="25" Margin="5" Maximum="100" Value="{Binding CurrentProgress}">

My data source would probably "jump" from value to value, usually from user input; for example - user performs action, and the progress bar jumps 20 points. I would want to be able to take the new number for ProgressBar.Value and smooth it over in the animation. Let's say the new value is 50 and the old value is 20. I would want some sort of XAML markup to dictate that the UI to smoothly slides from 20 to 50.

I want to do this declaratively with no code-behind. I'm fairly sure it's possible but I can't seem to fit in the pieces together. I have looked into Storyboards, but don't know how to trigger a storyboard when data changes. I have also looked into the TransitioningContentControl but am unsure how to link the transition with the ProgressBar control.

Try to add animation in ProgressBars Template event triger

<EventTrigger RoutedEvent="RangeBase.ValueChanged">
 <BeginStoryboard Storyboard="{StaticResource OnValueChanged1}"/>
</EventTrigger>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM