【发布时间】:2014-05-09 13:40:54
【问题描述】:
在 MainWindow.xaml 我有这个:
<view:CircularProgressBar Percentage="25"
...
x:Name="speedoBar"/>
我将百分比绑定到我从更远的外部获得的值。问题是:它直接设置值,但我需要一个 DoubleAnimation 从我现在的位置到我刚刚得到的值。
在获得价值的部分中,我尝试创建一个新的 Storyboard 和 DoubleAnimation,但我没有尝试任何工作。 我可以考虑创建一个新的 DependencyProperty 变量,该变量将是 DoubleAnimated 并将 Percentage 绑定到它。但是这个值是双精度值,我无法将 DoubleAnimation 启动为通常的双精度值。我在互联网上只能找到对象 DpendencyProperty 的 DoubleAnimation。
然后我尝试在百分比值上制作动画,但代码隐藏无法识别它,VisualStudio 建议创建一个新的 DependencyProperty-variable。
到目前为止,我所拥有的是:
// get the old value
speedCopy = speedoBar.Percentage;
DoubleAnimation speedDoubleAni =
new DoubleAnimation(speedCopy, (double)(vehicleDataViewModel.Speed), new Duration(new TimeSpan(0, 0, 10)));
Storyboard.SetTargetName(speedDoubleAni, "speedoBar.Percentage");
Storyboard.SetTargetProperty(speedDoubleAni, new PropertyPath(DoubleAnimation.ByProperty));
Storyboard story = new Storyboard();
story.Children.Add(speedDoubleAni);
story.Begin();
但它不起作用并在story.Begin(); 处显示错误,这意味着更难找出真正的问题 D:
那么你会怎么做呢?我在这里做错了什么?
【问题讨论】:
标签: c# wpf wpf-animation doubleanimation