2012-03-05 15 views
0

私は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)") 

そしていくつかの他、私はゼロ運を持っていますこの。

誰かが間違っているのを誰でも見ることができますか?私は前にMapShape.FillPropertyにデータバインディング行っている

おかげで、 ジャック

+0

コードに問題はありません。実行するとどうなりますか?任意のエラー?例外? – ColinE

+0

コードはRectangleに対して正常に機能します。おそらくこれはMapShapeをアニメートする際の問題です。 – foson

+0

返信ありがとうございますFosonとColinE ColinE:エラーはありません。何もしません。 Foson:MapShapeオブジェクトで、思考が変わるかどうかはわかりませんが、Controlオブジェクトを継承していますか? – Jacques

答えて

1

試してみてください。

 //create double animation 
     ColorAnimation animation = new ColorAnimation(); 

     //set the duration property 
     animation.Duration = duration; 

     //set the from and too values 
     animation.From = Colors.Purple; 
     animation.To = Colors.Transparent; 

     //add the duration to the storyboard 
     story.Duration = duration; 

     //now set the target of the animation 
     Storyboard.SetTarget(animation, rect); 

     //set the target property of this object 
     Storyboard.SetTargetProperty(animation, new PropertyPath("(MapShape.Fill).Color")); 

EDITは:あなたのコードが動作していない理由については

- MapShape.SetShapeFillStroke()を介して見ると、TelerikがMapShapeの不透明度を結合しないことが表示されますあなたが塗りつぶしを提供しない限り、内部プリミティブシェイプの不透明度に変換します。 XAMLでFillが定義されていますか?そうでない場合は、提供してください。さもなければ、コードがShapeのライフサイクルの早すぎる(ReadCompletedの中または後で)定義されている可能性がありますか?

<telerik:InformationLayer x:Name="StateLayer"> 
    <telerik:InformationLayer.Reader> 
     ... 
    </telerik:InformationLayer.Reader> 
    <telerik:InformationLayer.ShapeFill> 
     <telerik:MapShapeFill Fill="{StaticResource CommonBackgroundLightBrush}" Stroke="#5A636B" StrokeThickness="1" /> 
    </telerik:InformationLayer.ShapeFill> 
+0

こんにちは、私はこれをすぐに試してみましょう。私の不透明度コードがうまくいかない理由は何ですか? – Jacques

+0

こんにちはFoson、私はあなたのコードを試してみましたが、マップの形状が透明に変わったということでしたが、時間が経つとアニメーション化されていないことは瞬時です。 TimeSpan.FromSeconds(5)...これは5秒間という意味ですか? – Jacques

+0

修正:全く動作しませんでしたが、実際はPropertyPathの.Color部分を入れていませんでした。私はそれを追加するときに例外が発生します:指定されたオブジェクトのTargetProperty(MapShape.Fill).Colorを解決できません。 – Jacques

関連する問題