【发布时间】:2012-03-23 02:11:40
【问题描述】:
我是 Silverlight 的新手,正在尝试以编程方式为对象的不透明度设置动画的示例。
我想出了以下代码:
MapShape myTestShape= RadMapInformationLayer.Items[0] as MapShape;
SolidColorBrush brush = new SolidColorBrush();
brush.Color = Colors.Purple;
myTestShape.Fill = brush;
//create a duration object
Duration duration = new Duration(TimeSpan.FromSeconds(5));
//create the storyboard
Storyboard story = new Storyboard();
//create double animation
DoubleAnimation animation = new DoubleAnimation();
//set the duration property
animation.Duration = duration;
//set the from and too values
animation.From = 1.0;
animation.To = 0.0;
//add the duration to the storyboard
story.Duration = duration;
//now set the target of the animation
Storyboard.SetTarget(animation, myTestShape);
//set the target property of this object
Storyboard.SetTargetProperty(animation, new PropertyPath(UIElement.OpacityProperty));
//add the double animations to the story board
story.Children.Add(animation);
if (!LayoutRoot.Resources.Contains("story1"))
LayoutRoot.Resources.Add("story1", story);
story.Begin();
对于我也尝试过的属性路径:
1. new PropertyPath("(FrameworkElement.Opacity)")
2. new PropertyPath("(FrameworkElement.Opacity)")
3. new PropertyPath("(Control.Opacity)")
还有其他一些人,我对此的运气为零。
谁能看出我哪里出错了?
谢谢, 雅克
【问题讨论】:
-
我看不出您的代码有任何问题。当你执行它时会发生什么?有什么错误吗?例外?
-
代码适用于矩形。也许这是为 MapShape 设置动画的问题。
-
感谢回复 Foson 和 ColinE ColinE: 没有错误,只是没有做任何事情 Foson: 可能是 MapShape 对象,不知道它是否会改变你的想法,但它继承了来自 Control 对象?
标签: silverlight animation telerik opacity