Storyboard..::.SetTargetProperty Method Home
.NET Framework Class Library for Silverlight
Storyboard..::.SetTargetProperty Method
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

Sets the target property for the Timeline element (e.g. animation element like DoubleAnimation).

Namespace:  System.Windows.Media.Animation
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Usage

Dim element As Timeline
Dim value As String

Storyboard.SetTargetProperty(element, _
    value)

'Declaration

Public Shared Sub SetTargetProperty ( _
    element As Timeline, _
    value As String _
)

Parameters

element
Type: System.Windows.Media.Animation..::.Timeline

The Timeline element.

value
Type: System..::.String

The property that is targeted by the Timeline element.

Remarks

In addition to setting the target property using this method, you must target the object that possesses that property using a method like SetTarget or SetTargetName.

Indirect target properties can be specified with a property path syntax. For details on this syntax, see Storyboard..::.TargetProperty.

Examples

The following example shows how to create a Storyboard using code.

        public void Create_And_Run_Animation(object sender, EventArgs e)
        {
            // Create a red rectangle that will be the target
            // of the animation.
            Rectangle myRectangle = new Rectangle();
            myRectangle.Width = 200;
            myRectangle.Height = 200;
            Color myColor = Color.FromArgb(255, 255, 0, 0);
            SolidColorBrush myBrush = new SolidColorBrush();
            myBrush.Color = myColor;
            myRectangle.Fill = myBrush;

            // Add the rectangle to the tree.
            LayoutRoot.Children.Add(myRectangle);

            // Create a duration of 2 seconds.
            Duration duration = new Duration(TimeSpan.FromSeconds(2.0));

            // Create two DoubleAnimations and set their properties.
            DoubleAnimation myDoubleAnimation1 = new DoubleAnimation();
            DoubleAnimation myDoubleAnimation2 = new DoubleAnimation();

            myDoubleAnimation1.Duration = duration;
            myDoubleAnimation2.Duration = duration;

            Storyboard sb = new Storyboard();
            sb.Duration = duration;

            sb.Children.Add(myDoubleAnimation1);
            sb.Children.Add(myDoubleAnimation2);

            Storyboard.SetTarget(myDoubleAnimation1, myRectangle);
            Storyboard.SetTarget(myDoubleAnimation2, myRectangle);

            // Set the attached properties of Canvas.Left and Canvas.Top
            // to be the target properties of the two respective DoubleAnimations
            Storyboard.SetTargetProperty(myDoubleAnimation1, "(Canvas.Left)");
            Storyboard.SetTargetProperty(myDoubleAnimation2, "(Canvas.Top)");

            myDoubleAnimation1.To = 200;
            myDoubleAnimation2.To = 200;

            // Make the Storyboard a resource.
            LayoutRoot.Resources.Add(sb);

            // Begin the animation.
            sb.Begin();
        }
See Also

Reference

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View