Jacques
Jacques

Reputation: 7135

Silverlight opacity animation not working programmatically

I'm new at Silverlight and trying samples for things animating the opacity of an object programatically.

I've come up with the following code:

        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();

For the property path I've also tried:

1.  new PropertyPath("(FrameworkElement.Opacity)")

2.  new PropertyPath("(FrameworkElement.Opacity)")

3.  new PropertyPath("(Control.Opacity)")

And a few others, I'm having zero luck with this.

Can anyone see where I'm going wrong?

Thanks, Jacques

Upvotes: 0

Views: 906

Answers (1)

foson
foson

Reputation: 10227

I have done databinding to MapShape.FillProperty before.

Try:

        //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:

As for why your code is not working -- Looking through MapShape.SetShapeFillStroke(), it appears that Telerik won't bind the MapShape's Opacity to its inner primitive shape's Opacity unless you provide a fill. Do you have a Fill defined in XAML? If not, try providing one. Otherwise, maybe the code is defined too early in the Shape's lifecycle (in or after 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>

Upvotes: 1

Related Questions