Silverlight不透明动画无法以编程方式工作

Silverlight不透明动画无法以编程方式工作,silverlight,animation,telerik,opacity,Silverlight,Animation,Telerik,Opacity,我是Silverlight的新手,正在尝试通过编程设置对象不透明度动画的示例 我想出了以下代码: MapShape myTestShape= RadMapInformationLayer.Items[0] as MapShape; SolidColorBrush brush = new SolidColorBrush(); brush.Color = Colors.Purple; myTestShape.Fill = brush;

我是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)")
还有一些人,我在这方面运气不佳

有人能看出我哪里做错了吗

谢谢,
Jacques

我以前已经对MapShape.FillProperty进行了数据绑定

尝试:

编辑:

至于代码不起作用的原因——查看MapShape.SetShapeFillStroke(),Telerik似乎不会将MapShape的不透明度绑定到其内部基本图形的不透明度,除非提供填充。您是否在XAML中定义了填充?如果没有,请尝试提供一个。否则,可能代码在形状的生命周期中定义得太早(在ReadCompleted中或之后)


...

我看不出您的代码有任何问题。执行时会发生什么?有错误吗?异常?对于矩形,代码可以正常工作。也许这是MapShape动画的问题。谢谢你的回复Foson和ColinE ColinE:没有错误,只是没有任何作用Foson:可能是MapShape对象,不确定它是否会改变你的想法,但它继承了控制对象?嗨Foson,我会很快尝试一下。我的不透明度代码不起作用的原因是什么?嗨,福森,我试过你的代码,成功的原因是贴图形状变为透明,但它肯定不会随着时间的推移而动画化,它是瞬时的。时间跨度。从秒(5)。。。这意味着5秒,对吗?更正:它根本不起作用,我实际上没有在PropertyPath中输入.Color部分。当我添加它时,我得到一个异常:无法解析指定对象上的TargetProperty(MapShape.Fill).Color。
        //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"));
<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>