我是Silverlight的新手,並嘗試通過編程方式爲對象的不透明度創建動畫樣本。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)")
和其他幾個人,我有零運氣這個。
任何人都可以看到我要去哪裏錯了嗎?
感謝, 雅克
我看不出您的代碼有任何問題。當你執行它時會發生什麼?任何錯誤?異常? – ColinE 2012-03-05 16:59:47
代碼適用於矩形。也許這是動畫MapShape的一個問題。 – foson 2012-03-05 21:53:43
感謝您的回覆Foson和ColinE ColinE:沒有錯誤,它只是沒有做任何事情 Foson:它可能是MapShape對象,不知道它是否會改變您的想法,但它從Control對象繼承? – Jacques 2012-03-06 12:52:27