Storyboard.Begin Método

Definición

Inicia el conjunto de animaciones asociadas a este Storyboard.

Sobrecargas

Begin(FrameworkElement, FrameworkTemplate, HandoffBehavior, Boolean)

Aplica las animaciones asociadas a este Storyboard a sus destinos dentro de la plantilla especificada y las inicia.

Begin(FrameworkElement, HandoffBehavior, Boolean)

Aplica las animaciones asociadas a este Storyboard a sus destinos y las inicia.

Begin(FrameworkElement, FrameworkTemplate, HandoffBehavior)

Aplica las animaciones asociadas a este Storyboard a sus destinos dentro de la plantilla especificada y las inicia.

Begin(FrameworkElement, FrameworkTemplate, Boolean)

Aplica las animaciones asociadas a este Storyboard a sus destinos dentro de la plantilla especificada y las inicia.

Begin(FrameworkContentElement, HandoffBehavior, Boolean)

Aplica las animaciones asociadas a este Storyboard a sus destinos e inicia, utilizando el HandoffBehaviorespecificado.

Begin(FrameworkElement, FrameworkTemplate)

Aplica las animaciones asociadas a este Storyboard a sus destinos dentro de la plantilla especificada y las inicia.

Begin(FrameworkElement, HandoffBehavior)

Aplica las animaciones asociadas a este Storyboard a sus destinos e inicia, utilizando el HandoffBehaviorespecificado.

Begin(FrameworkContentElement, HandoffBehavior)

Aplica las animaciones asociadas a este Storyboard a sus destinos e inicia, utilizando el HandoffBehaviorespecificado.

Begin(FrameworkContentElement, Boolean)

Aplica las animaciones asociadas a este Storyboard a sus destinos y las inicia.

Begin(FrameworkElement)

Aplica las animaciones asociadas a este Storyboard a sus destinos y las inicia.

Begin(FrameworkContentElement)

Aplica las animaciones asociadas a este Storyboard a sus destinos y las inicia.

Begin()

Aplica las animaciones asociadas a este Storyboard a sus destinos y las inicia.

Begin(FrameworkElement, Boolean)

Aplica las animaciones asociadas a este Storyboard a sus destinos y las inicia.

Comentarios

Un guión gráfico controlable puede pausar, reanudar, buscar, detener y quitarse. Para que un guión gráfico pueda controlarse en el código, debe usar la sobrecarga adecuada del método Begin del guión gráfico y especificar true para que sea controlable. Para obtener un ejemplo, vea Cómo: Controlar un guión gráfico después de que se inicie.

Begin(FrameworkElement, FrameworkTemplate, HandoffBehavior, Boolean)

Aplica las animaciones asociadas a este Storyboard a sus destinos dentro de la plantilla especificada y las inicia.

C#
public void Begin (System.Windows.FrameworkElement containingObject, System.Windows.FrameworkTemplate frameworkTemplate, System.Windows.Media.Animation.HandoffBehavior handoffBehavior, bool isControllable);

Parámetros

containingObject
FrameworkElement

Objeto al que se ha aplicado el frameworkTemplate especificado. Las animaciones sin un TargetName se aplican a containingObject.

frameworkTemplate
FrameworkTemplate

Plantilla que se va a animar.

handoffBehavior
HandoffBehavior

El comportamiento que debe usar la nueva animación para interactuar con las animaciones actuales.

isControllable
Boolean

true si el guión gráfico debe controlarse de forma interactiva; de lo contrario, false.

Comentarios

Para controlar interactivamente este guión gráfico, debe especificar el mismo containingObject al llamar a los métodos interactivos que usó para comenzar el guión gráfico.

Cuando se llama a este método, se crean Clock objetos para el guión gráfico y las escalas de tiempo que contiene. Estos relojes se almacenan con containingObject.

Al iniciar un guión gráfico, se desencadenan los eventos CurrentStateInvalidated y CurrentGlobalSpeedInvalidated.

Uso de Compose HandoffBehavior

Cuando se aplica un Storyboard, AnimationTimelineo AnimationClock a una propiedad mediante el ComposeHandoffBehavior, los objetos Clock asociados previamente a esa propiedad siguen usando recursos del sistema; el sistema de control de tiempo no quita automáticamente estos relojes.

Para evitar problemas de rendimiento al aplicar un gran número de relojes mediante Compose, debe quitar la composición de los relojes de la propiedad animada después de completarlos. Hay varias maneras de quitar un reloj.

Esto es principalmente un problema para animaciones en objetos que tienen una larga duración. Cuando se recopila un objeto, sus relojes también se desconectan y se recopilan elementos no utilizados.

Para obtener más información sobre los objetos de reloj, vea Animation and Timing System Overview.

Se aplica a

.NET Framework 4.8.1 y otras versiones
Producto Versiones
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Begin(FrameworkElement, HandoffBehavior, Boolean)

Aplica las animaciones asociadas a este Storyboard a sus destinos y las inicia.

C#
public void Begin (System.Windows.FrameworkElement containingObject, System.Windows.Media.Animation.HandoffBehavior handoffBehavior, bool isControllable);

Parámetros

containingObject
FrameworkElement

Objeto contenido en el mismo ámbito de nombre que los destinos de las animaciones de este guión gráfico. Las animaciones sin un TargetName especificado se aplican a containingObject.

handoffBehavior
HandoffBehavior

El comportamiento que debe usar la nueva animación para interactuar con las animaciones actuales.

isControllable
Boolean

Declara si la animación es controlable (se puede pausar) una vez iniciada.

Ejemplos

En el ejemplo siguiente se muestra cómo crear un guión gráfico controlable.

C#
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows.Media.Animation;

namespace SDKSample
{

    public class ControllableStoryboardExample : Page
    {
        private Storyboard myStoryboard;

        public ControllableStoryboardExample()
        {

            // Create a name scope for the page.

            NameScope.SetNameScope(this, new NameScope()); 
 
            this.WindowTitle = "Controllable Storyboard Example";
            StackPanel myStackPanel = new StackPanel();
            myStackPanel.Margin = new Thickness(10);

            // Create a rectangle.
            Rectangle myRectangle = new Rectangle();
            myRectangle.Name = "myRectangle";

            // Assign the rectangle a name by 
            // registering it with the page, so that
            // it can be targeted by storyboard
            // animations.
            this.RegisterName(myRectangle.Name, myRectangle);
            myRectangle.Width = 100;
            myRectangle.Height = 100;
            myRectangle.Fill = Brushes.Blue;
            myStackPanel.Children.Add(myRectangle);

            //
            // Create an animation and a storyboard to animate the
            // rectangle.
            //
            DoubleAnimation myDoubleAnimation = new DoubleAnimation();
            myDoubleAnimation.From = 1.0;
            myDoubleAnimation.To = 0.0;
            myDoubleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(5000));
            myDoubleAnimation.AutoReverse = true;

            // Create the storyboard.
            myStoryboard = new Storyboard();
            myStoryboard.Children.Add(myDoubleAnimation);
            Storyboard.SetTargetName(myDoubleAnimation, myRectangle.Name);
            Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(Rectangle.OpacityProperty));

            //
            // Create some buttons to control the storyboard
            // and a panel to contain them.
            //
            StackPanel buttonPanel = new StackPanel();
            buttonPanel.Orientation = Orientation.Horizontal;
            Button beginButton = new Button();
            beginButton.Content = "Begin";
            beginButton.Click += new RoutedEventHandler(beginButton_Clicked);
            buttonPanel.Children.Add(beginButton);
            Button pauseButton = new Button();
            pauseButton.Content = "Pause";
            pauseButton.Click += new RoutedEventHandler(pauseButton_Clicked);
            buttonPanel.Children.Add(pauseButton);
            Button resumeButton = new Button();
            resumeButton.Content = "Resume";
            resumeButton.Click += new RoutedEventHandler(resumeButton_Clicked);
            buttonPanel.Children.Add(resumeButton);
            Button skipToFillButton = new Button();
            skipToFillButton.Content = "Skip to Fill";
            skipToFillButton.Click += new RoutedEventHandler(skipToFillButton_Clicked);
            buttonPanel.Children.Add(skipToFillButton);
            Button setSpeedRatioButton = new Button();
            setSpeedRatioButton.Content = "Triple Speed";
            setSpeedRatioButton.Click += new RoutedEventHandler(setSpeedRatioButton_Clicked);
            buttonPanel.Children.Add(setSpeedRatioButton);
            Button stopButton = new Button();
            stopButton.Content = "Stop";
            stopButton.Click += new RoutedEventHandler(stopButton_Clicked);
            buttonPanel.Children.Add(stopButton);
            myStackPanel.Children.Add(buttonPanel);
            this.Content = myStackPanel;        
        }

        // Begins the storyboard.
        private void beginButton_Clicked(object sender, RoutedEventArgs args)
        {
            // Specifying "true" as the second Begin parameter
            // makes this storyboard controllable.
            myStoryboard.Begin(this, true);
        }

        // Pauses the storyboard.
        private void pauseButton_Clicked(object sender, RoutedEventArgs args)
        {
            myStoryboard.Pause(this);
        }

        // Resumes the storyboard.
        private void resumeButton_Clicked(object sender, RoutedEventArgs args)
        {
            myStoryboard.Resume(this);
        }

        // Advances the storyboard to its fill period.
        private void skipToFillButton_Clicked(object sender, RoutedEventArgs args)
        {
            myStoryboard.SkipToFill(this);
        }

        // Updates the storyboard's speed.
        private void setSpeedRatioButton_Clicked(object sender, RoutedEventArgs args)
        {
            // Makes the storyboard progress three times as fast as normal.
            myStoryboard.SetSpeedRatio(this, 3);
        }

        // Stops the storyboard.
        private void stopButton_Clicked(object sender, RoutedEventArgs args)
        {
            myStoryboard.Stop(this);
        }         
    }
}

En el ejemplo siguiente se usa el SnapshotAndReplaceHandoffBehavior para animar cuando el usuario hace clic con el botón izquierdo y el ComposeHandoffBehavior cuando el usuario hace clic con el botón derecho.

C#
/*

   This sample animates the position of an ellipse when 
   the user clicks within the main border. If the user
   left-clicks, the SnapshotAndReplace HandoffBehavior
   is used when applying the animations. If the user
   right-clicks, the Compose HandoffBehavior is used
   instead.

*/

using System;
using System.Windows;
using System.Windows.Navigation;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Controls;
using System.Windows.Input;

namespace Microsoft.Samples.Animation.AnimatingWithStoryboards
{

    // Create the demonstration.
    public class FrameworkElementStoryboardHandoffBehaviorExample : Page {

        private Border containerBorder;
        private Ellipse interactiveEllipse;
        private Storyboard theStoryboard;
        private DoubleAnimation xAnimation;
        private DoubleAnimation yAnimation;
        
        public FrameworkElementStoryboardHandoffBehaviorExample()
        {
        
            WindowTitle = "Interactive Animation Example";
            
            // Create a name scope for the page.
            NameScope.SetNameScope(this, new NameScope());  
            
            DockPanel myPanel = new DockPanel();
            myPanel.Margin = new Thickness(20.0);            
    
            containerBorder = new Border();
            containerBorder.Background = Brushes.White;
            containerBorder.BorderBrush = Brushes.Black;
            containerBorder.BorderThickness = new Thickness(2.0); 
            containerBorder.VerticalAlignment = VerticalAlignment.Stretch;
            
            interactiveEllipse = new Ellipse();
            interactiveEllipse.Fill = Brushes.Lime;
            interactiveEllipse.Stroke = Brushes.Black;
            interactiveEllipse.StrokeThickness = 2.0;
            interactiveEllipse.Width = 25;
            interactiveEllipse.Height = 25;
            interactiveEllipse.HorizontalAlignment = HorizontalAlignment.Left;
            interactiveEllipse.VerticalAlignment = VerticalAlignment.Top;

            TranslateTransform interactiveTranslateTransform = new TranslateTransform();       
            this.RegisterName("InteractiveTranslateTransform", interactiveTranslateTransform);
            
            interactiveEllipse.RenderTransform = 
                interactiveTranslateTransform;
                
            xAnimation = new DoubleAnimation();
            xAnimation.Duration = TimeSpan.FromSeconds(4);
            yAnimation = xAnimation.Clone();
            Storyboard.SetTargetName(xAnimation, "InteractiveTranslateTransform");
            Storyboard.SetTargetProperty(xAnimation, new PropertyPath(TranslateTransform.XProperty));
            Storyboard.SetTargetName(yAnimation, "InteractiveTranslateTransform");
            Storyboard.SetTargetProperty(yAnimation, new PropertyPath(TranslateTransform.YProperty));            
            
            theStoryboard = new Storyboard();
            theStoryboard.Children.Add(xAnimation);
            theStoryboard.Children.Add(yAnimation);

            containerBorder.MouseLeftButtonDown += 
                new MouseButtonEventHandler(border_mouseLeftButtonDown);
            containerBorder.MouseRightButtonDown += 
                new MouseButtonEventHandler(border_mouseRightButtonDown);                
            
            containerBorder.Child = interactiveEllipse;
            myPanel.Children.Add(containerBorder);
            this.Content = myPanel;
        }

        // When the user left-clicks, use the 
        // SnapshotAndReplace HandoffBehavior when applying the animation.        
        private void border_mouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
        
            Point clickPoint = Mouse.GetPosition(containerBorder);
            
            // Set the target point so the center of the ellipse
            // ends up at the clicked point.
            Point targetPoint = new Point();
            targetPoint.X = clickPoint.X - interactiveEllipse.Width / 2;
            targetPoint.Y = clickPoint.Y - interactiveEllipse.Height / 2;  
            
            // Animate to the target point.
            xAnimation.To = targetPoint.X;
            yAnimation.To = targetPoint.Y;
            theStoryboard.Begin(this, HandoffBehavior.SnapshotAndReplace);

            // Change the color of the ellipse.
            interactiveEllipse.Fill = Brushes.Lime;
        }
        
        // When the user right-clicks, use the 
        // Compose HandoffBehavior when applying the animation.
        private void border_mouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
        
            // Find the point where the use clicked.
            Point clickPoint = Mouse.GetPosition(containerBorder);
            
            // Set the target point so the center of the ellipse
            // ends up at the clicked point.
            Point targetPoint = new Point();
            targetPoint.X = clickPoint.X - interactiveEllipse.Width / 2;
            targetPoint.Y = clickPoint.Y - interactiveEllipse.Height / 2;
 
            // Animate to the target point.
            xAnimation.To = targetPoint.X;
            yAnimation.To = targetPoint.Y;
            theStoryboard.Begin(this, HandoffBehavior.Compose);
                
            // Change the color of the ellipse.
            interactiveEllipse.Fill = Brushes.Orange;
        }
    }
}

Comentarios

Para controlar interactivamente este guión gráfico, debe usar el mismo parámetro containingObject al llamar a los métodos interactivos que usó para comenzar el guión gráfico.

Cuando se llama a este método, se crean Clock objetos para el guión gráfico y las escalas de tiempo que contiene. Estos relojes se almacenan con containingObject.

Al iniciar un guión gráfico, se desencadenan los eventos CurrentStateInvalidated y CurrentGlobalSpeedInvalidated.

Uso de Compose HandoffBehavior

Cuando se aplica un Storyboard, AnimationTimelineo AnimationClock a una propiedad mediante el ComposeHandoffBehavior, los objetos Clock asociados previamente a esa propiedad siguen usando recursos del sistema; el sistema de control de tiempo no quita automáticamente estos relojes.

Para evitar problemas de rendimiento al aplicar un gran número de relojes mediante Compose, debe quitar la composición de los relojes de la propiedad animada después de completarlos. Hay varias maneras de quitar un reloj.

Esto es principalmente un problema para animaciones en objetos que tienen una larga duración. Cuando se recopila un objeto, sus relojes también se desconectan y se recopilan elementos no utilizados.

Para obtener más información sobre los objetos de reloj, vea Animation and Timing System Overview.

Se aplica a

.NET Framework 4.8.1 y otras versiones
Producto Versiones
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Begin(FrameworkElement, FrameworkTemplate, HandoffBehavior)

Aplica las animaciones asociadas a este Storyboard a sus destinos dentro de la plantilla especificada y las inicia.

C#
public void Begin (System.Windows.FrameworkElement containingObject, System.Windows.FrameworkTemplate frameworkTemplate, System.Windows.Media.Animation.HandoffBehavior handoffBehavior);

Parámetros

containingObject
FrameworkElement

Objeto al que se ha aplicado el frameworkTemplate especificado. Las animaciones sin un TargetName se aplican a containingObject.

frameworkTemplate
FrameworkTemplate

Plantilla que se va a animar.

handoffBehavior
HandoffBehavior

El comportamiento que debe usar la nueva animación para interactuar con las animaciones actuales.

Comentarios

Cuando se llama a este método, se crean Clock objetos para el guión gráfico y las escalas de tiempo que contiene. Estos relojes se almacenan con containingObject.

Al iniciar un guión gráfico, se desencadenan los eventos CurrentStateInvalidated y CurrentGlobalSpeedInvalidated.

Uso de Compose HandoffBehavior

Cuando se aplica un Storyboard, AnimationTimelineo AnimationClock a una propiedad mediante el ComposeHandoffBehavior, los objetos Clock asociados previamente a esa propiedad siguen usando recursos del sistema; el sistema de control de tiempo no quita automáticamente estos relojes.

Para evitar problemas de rendimiento al aplicar un gran número de relojes mediante Compose, debe quitar la composición de los relojes de la propiedad animada después de completarlos. Hay varias maneras de quitar un reloj.

Esto es principalmente un problema para animaciones en objetos que tienen una larga duración. Cuando se recopila un objeto, sus relojes también se desconectan y se recopilan elementos no utilizados.

Para obtener más información sobre los objetos de reloj, vea Animation and Timing System Overview.

Se aplica a

.NET Framework 4.8.1 y otras versiones
Producto Versiones
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Begin(FrameworkElement, FrameworkTemplate, Boolean)

Aplica las animaciones asociadas a este Storyboard a sus destinos dentro de la plantilla especificada y las inicia.

C#
public void Begin (System.Windows.FrameworkElement containingObject, System.Windows.FrameworkTemplate frameworkTemplate, bool isControllable);

Parámetros

containingObject
FrameworkElement

Objeto al que se ha aplicado el frameworkTemplate especificado. Las animaciones sin un TargetName se aplican a containingObject.

frameworkTemplate
FrameworkTemplate

Plantilla que se va a animar.

isControllable
Boolean

true si el guión gráfico debe controlarse de forma interactiva; de lo contrario, false.

Comentarios

Si las propiedades de destino ya están animadas, se reemplazan mediante el comportamiento de entrega SnapshotAndReplace.

Para controlar interactivamente este guión gráfico, debe especificar el mismo containingObject al llamar a los métodos interactivos que usó para comenzar el guión gráfico.

Cuando se llama a este método, se crean Clock objetos para el guión gráfico y las escalas de tiempo que contiene. Estos relojes se almacenan con containingObject.

Al iniciar un guión gráfico, se desencadenan los eventos CurrentStateInvalidated y CurrentGlobalSpeedInvalidated.

Se aplica a

.NET Framework 4.8.1 y otras versiones
Producto Versiones
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Begin(FrameworkContentElement, HandoffBehavior, Boolean)

Aplica las animaciones asociadas a este Storyboard a sus destinos e inicia, utilizando el HandoffBehaviorespecificado.

C#
public void Begin (System.Windows.FrameworkContentElement containingObject, System.Windows.Media.Animation.HandoffBehavior handoffBehavior, bool isControllable);

Parámetros

containingObject
FrameworkContentElement

Objeto contenido en el mismo ámbito de nombre que los destinos de las animaciones de este guión gráfico. Las animaciones sin un TargetName especificado se aplican a containingObject.

handoffBehavior
HandoffBehavior

El comportamiento que debe usar la nueva animación para interactuar con las animaciones actuales.

isControllable
Boolean

Declara si la animación es controlable (se puede pausar) una vez iniciada.

Ejemplos

En el ejemplo siguiente se usa un guión gráfico controlable para animar un TextEffect. El TextEffect se encuentra dentro de un ámbito de nombre de FrameworkContentElement.

C#
/*
    This example shows how to control
    a storyboard after it has started.

*/

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Windows.Documents;

namespace Microsoft.Samples.Animation.AnimatingWithStoryboards
{
    public class FrameworkContentElementControlStoryboardExample : FlowDocument
    {
    
        private Storyboard myStoryboard;
        
        public FrameworkContentElementControlStoryboardExample()
        {
        
            // Create a name scope for the document.
            NameScope.SetNameScope(this, new NameScope());        
            this.Background = Brushes.White;
            
            // Create a run of text.
            Run theText = new Run( 
                "Lorem ipsum dolor sit amet, consectetuer adipiscing elit." + 
                "Ut non lacus. Nullam a ligula id leo adipiscing ornare." +
                " Duis mattis. ");   
                
            // Create a TextEffect
            TextEffect animatedSpecialEffect = new TextEffect();
            animatedSpecialEffect.Foreground = Brushes.OrangeRed;
            animatedSpecialEffect.PositionStart = 0;
            animatedSpecialEffect.PositionCount = 0;
            
            // Assign the TextEffect a name by 
            // registering it with the page, so that
            // it can be targeted by storyboard
            // animations            
            this.RegisterName("animatedSpecialEffect", animatedSpecialEffect);  
            
            // Apply the text effect to the run.
            theText.TextEffects = new TextEffectCollection();
            theText.TextEffects.Add(animatedSpecialEffect);
            
            // Create a paragraph to contain the run.
            Paragraph animatedParagraph = new Paragraph(theText);
            animatedParagraph.Background = Brushes.LightGray;
            animatedParagraph.Padding = new Thickness(20);
   
            this.Blocks.Add(animatedParagraph);            
            BlockUIContainer controlsContainer = new BlockUIContainer();                
            
            //
            // Create an animation and a storyboard to animate the
            // text effect.
            //
            Int32Animation countAnimation = 
                new Int32Animation(0, 127, TimeSpan.FromSeconds(10)); 
            Storyboard.SetTargetName(countAnimation, "animatedSpecialEffect");
            Storyboard.SetTargetProperty(countAnimation, 
                new PropertyPath(TextEffect.PositionCountProperty));
            myStoryboard = new Storyboard();
            myStoryboard.Children.Add(countAnimation);
            
            //
            // Create some buttons to control the storyboard
            // and a panel to contain them.
            //
            StackPanel buttonPanel = new StackPanel();
            buttonPanel.Orientation = Orientation.Vertical;
            Button beginButton = new Button();
            beginButton.Content = "Begin";
            beginButton.Click += new RoutedEventHandler(beginButton_Clicked);            
            buttonPanel.Children.Add(beginButton);
            Button pauseButton = new Button();
            pauseButton.Content = "Pause";
            pauseButton.Click +=new RoutedEventHandler(pauseButton_Clicked);
            buttonPanel.Children.Add(pauseButton);
            Button resumeButton = new Button();
            resumeButton.Content = "Resume";
            resumeButton.Click +=new RoutedEventHandler(resumeButton_Clicked);
            buttonPanel.Children.Add(resumeButton);
            Button skipToFillButton = new Button();
            skipToFillButton.Content = "Skip to Fill";
            skipToFillButton.Click +=new RoutedEventHandler(skipToFillButton_Clicked);
            buttonPanel.Children.Add(skipToFillButton);
            Button setSpeedRatioButton = new Button();
            setSpeedRatioButton.Content = "Triple Speed";
            setSpeedRatioButton.Click +=new RoutedEventHandler(setSpeedRatioButton_Clicked);
            buttonPanel.Children.Add(setSpeedRatioButton);
            Button stopButton = new Button();
            stopButton.Content = "Stop";
            stopButton.Click +=new RoutedEventHandler(stopButton_Clicked);
            buttonPanel.Children.Add(stopButton);
            Button removeButton = new Button();
            removeButton.Content = "Remove";
            removeButton.Click +=new RoutedEventHandler(removeButton_Clicked);
            buttonPanel.Children.Add(removeButton); 
   
            controlsContainer.Child = buttonPanel; 
            this.Blocks.Add(controlsContainer);
        }
        
        // Begins the storyboard.
        private void beginButton_Clicked(object sender, RoutedEventArgs args)
        {
            // Specifying "true" as the second Begin parameter
            // makes this storyboard controllable.
            myStoryboard.Begin(this, true);          
        }
        
        // Pauses the storyboard.
        private void pauseButton_Clicked(object sender, RoutedEventArgs args)
        {
             myStoryboard.Pause(this);          
        }
        
        // Resumes the storyboard.
        private void resumeButton_Clicked(object sender, RoutedEventArgs args)
        {
             myStoryboard.Resume(this);          
        }     
        
        // Advances the storyboard to its fill period.
        private void skipToFillButton_Clicked(object sender, RoutedEventArgs args)
        {
             myStoryboard.SkipToFill(this);          
        } 
        
        // Updates the storyboard's speed.
        private void setSpeedRatioButton_Clicked(object sender, RoutedEventArgs args)
        {
            // Makes the storyboard progress three times as fast as normal.
            myStoryboard.SetSpeedRatio(this, 3);          
        }           
        
        // Stops the storyboard.
        private void stopButton_Clicked(object sender, RoutedEventArgs args)
        {
             myStoryboard.Stop(this);          
        }     
        
        // Removes the storyboard.
        private void removeButton_Clicked(object sender, RoutedEventArgs args)
        {
             myStoryboard.Remove(this);          
        }           
    }
}

En el ejemplo siguiente se usa el SnapshotAndReplaceHandoffBehavior para animar cuando el usuario hace clic con el botón izquierdo y el ComposeHandoffBehavior cuando el usuario hace clic con el botón derecho.

C#
/*
    This example shows how to animate
    a FrameworkContentElement with a storyboard.

*/

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Windows.Documents;
using System.Windows.Input;

namespace Microsoft.Samples.Animation.AnimatingWithStoryboards
{
    public class FrameworkContentElementStoryboardWithHandoffBehaviorExample : 
        FlowDocument
    {
    
        private Storyboard myStoryboard;
        DoubleAnimation xAnimation;
        DoubleAnimation yAnimation;
        
        public FrameworkContentElementStoryboardWithHandoffBehaviorExample()
        {
        
            // Create a name scope for the document.
            NameScope.SetNameScope(this, new NameScope());        
            this.Background = Brushes.Orange;
            
            // Create a run of text.
            Run theText = new Run( 
                "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.");   
                
            // Create a TextEffect
            TextEffect animatedSpecialEffect = new TextEffect();
            animatedSpecialEffect.Foreground = Brushes.OrangeRed;
            animatedSpecialEffect.PositionStart = 0;
            animatedSpecialEffect.PositionCount = 20;
            
            TranslateTransform animatedTransform = 
                new TranslateTransform();
                
            // Assign the transform a name by 
            // registering it with the page, so that
            // it can be targeted by storyboard
            // animations.      
            this.RegisterName("animatedTransform", animatedTransform);             
            animatedSpecialEffect.Transform = animatedTransform;

            // Apply the text effect to the run.
            theText.TextEffects = new TextEffectCollection();
            theText.TextEffects.Add(animatedSpecialEffect);

            // Create a paragraph to contain the run.
            Paragraph animatedParagraph = new Paragraph(theText);
            animatedParagraph.Background = Brushes.LightGray;           
   
            this.Blocks.Add(animatedParagraph);                           
            
            //
            // Create a storyboard to animate the
            // text effect's transform.
            //
            myStoryboard = new Storyboard();
            
            xAnimation = new DoubleAnimation();  
            xAnimation.Duration = TimeSpan.FromSeconds(5);                        
            Storyboard.SetTargetName(xAnimation, "animatedTransform");
            Storyboard.SetTargetProperty(xAnimation, 
                new PropertyPath(TranslateTransform.XProperty));      
            myStoryboard.Children.Add(xAnimation);
            
            yAnimation = new DoubleAnimation();
            yAnimation.Duration = TimeSpan.FromSeconds(5);           
            Storyboard.SetTargetName(yAnimation, "animatedTransform");
            Storyboard.SetTargetProperty(yAnimation, 
                new PropertyPath(TranslateTransform.YProperty));      
            myStoryboard.Children.Add(yAnimation);            
            
            this.MouseLeftButtonDown += 
                new MouseButtonEventHandler(document_mouseLeftButtonDown);
            this.MouseRightButtonDown += 
                new MouseButtonEventHandler(document_mouseRightButtonDown);
        }

        // When the user left-clicks, use the 
        // SnapshotAndReplace HandoffBehavior when applying the animation.        
        private void document_mouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
        
            Point clickPoint = Mouse.GetPosition(this);

            // Animate to the target point.
            xAnimation.To = clickPoint.X; 
            yAnimation.To = clickPoint.Y;

            try
            {
                myStoryboard.Begin(this, HandoffBehavior.SnapshotAndReplace);  
            }catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        
        // When the user right-clicks, use the 
        // Compose HandoffBehavior when applying the animation.
        private void document_mouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {

            Point clickPoint = Mouse.GetPosition(this);

            // Animate to the target point.
            xAnimation.To = clickPoint.X;
            yAnimation.To = clickPoint.Y;
            myStoryboard.Begin(this, HandoffBehavior.Compose);  
        }        
    }
}

Comentarios

Si las propiedades de destino ya están animadas, se reemplazan mediante el comportamiento de entrega especificado.

Para controlar interactivamente este guión gráfico, debe especificar el mismo containingObject al llamar a los métodos interactivos que usó para comenzar el guión gráfico.

Cuando se llama a este método, se crean Clock objetos para el guión gráfico y las escalas de tiempo que contiene. Estos relojes se almacenan con containingObject.

Al iniciar un guión gráfico, se desencadenan los eventos CurrentStateInvalidated y CurrentGlobalSpeedInvalidated.

Uso de Compose HandoffBehavior

Cuando se aplica un Storyboard, AnimationTimelineo AnimationClock a una propiedad mediante el ComposeHandoffBehavior, los objetos Clock asociados previamente a esa propiedad siguen usando recursos del sistema; el sistema de control de tiempo no quita automáticamente estos relojes.

Para evitar problemas de rendimiento al aplicar un gran número de relojes mediante Compose, debe quitar la composición de los relojes de la propiedad animada después de completarlos. Hay varias maneras de quitar un reloj.

Esto es principalmente un problema para animaciones en objetos que tienen una larga duración. Cuando se recopila un objeto, sus relojes también se desconectan y se recopilan elementos no utilizados.

Para obtener más información sobre los objetos de reloj, vea Animation and Timing System Overview.

Se aplica a

.NET Framework 4.8.1 y otras versiones
Producto Versiones
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Begin(FrameworkElement, FrameworkTemplate)

Aplica las animaciones asociadas a este Storyboard a sus destinos dentro de la plantilla especificada y las inicia.

C#
public void Begin (System.Windows.FrameworkElement containingObject, System.Windows.FrameworkTemplate frameworkTemplate);

Parámetros

containingObject
FrameworkElement

Objeto al que se ha aplicado el frameworkTemplate especificado. Las animaciones sin un TargetName se aplican a containingObject.

frameworkTemplate
FrameworkTemplate

Plantilla que se va a animar.

Comentarios

Si las propiedades de destino ya están animadas, se reemplazan mediante el comportamiento de entrega SnapshotAndReplace.

Cuando se llama a este método, se crean Clock objetos para el guión gráfico y las escalas de tiempo que contiene. Estos relojes se almacenan con containingObject.

Al iniciar un guión gráfico, se desencadenan los eventos CurrentStateInvalidated y CurrentGlobalSpeedInvalidated.

Se aplica a

.NET Framework 4.8.1 y otras versiones
Producto Versiones
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Begin(FrameworkElement, HandoffBehavior)

Aplica las animaciones asociadas a este Storyboard a sus destinos e inicia, utilizando el HandoffBehaviorespecificado.

C#
public void Begin (System.Windows.FrameworkElement containingObject, System.Windows.Media.Animation.HandoffBehavior handoffBehavior);

Parámetros

containingObject
FrameworkElement

Objeto contenido en el mismo ámbito de nombre que los destinos de las animaciones de este guión gráfico. Las animaciones sin un TargetName especificado se aplican a containingObject.

handoffBehavior
HandoffBehavior

El comportamiento que debe usar la nueva animación para interactuar con las animaciones actuales.

Ejemplos

En el ejemplo siguiente se usa el SnapshotAndReplaceHandoffBehavior para animar cuando el usuario hace clic con el botón izquierdo y el ComposeHandoffBehavior cuando el usuario hace clic con el botón derecho.

C#
/*

   This sample animates the position of an ellipse when 
   the user clicks within the main border. If the user
   left-clicks, the SnapshotAndReplace HandoffBehavior
   is used when applying the animations. If the user
   right-clicks, the Compose HandoffBehavior is used
   instead.

*/

using System;
using System.Windows;
using System.Windows.Navigation;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Controls;
using System.Windows.Input;

namespace Microsoft.Samples.Animation.AnimatingWithStoryboards
{

    // Create the demonstration.
    public class FrameworkElementStoryboardHandoffBehaviorExample : Page {

        private Border containerBorder;
        private Ellipse interactiveEllipse;
        private Storyboard theStoryboard;
        private DoubleAnimation xAnimation;
        private DoubleAnimation yAnimation;
        
        public FrameworkElementStoryboardHandoffBehaviorExample()
        {
        
            WindowTitle = "Interactive Animation Example";
            
            // Create a name scope for the page.
            NameScope.SetNameScope(this, new NameScope());  
            
            DockPanel myPanel = new DockPanel();
            myPanel.Margin = new Thickness(20.0);            
    
            containerBorder = new Border();
            containerBorder.Background = Brushes.White;
            containerBorder.BorderBrush = Brushes.Black;
            containerBorder.BorderThickness = new Thickness(2.0); 
            containerBorder.VerticalAlignment = VerticalAlignment.Stretch;
            
            interactiveEllipse = new Ellipse();
            interactiveEllipse.Fill = Brushes.Lime;
            interactiveEllipse.Stroke = Brushes.Black;
            interactiveEllipse.StrokeThickness = 2.0;
            interactiveEllipse.Width = 25;
            interactiveEllipse.Height = 25;
            interactiveEllipse.HorizontalAlignment = HorizontalAlignment.Left;
            interactiveEllipse.VerticalAlignment = VerticalAlignment.Top;

            TranslateTransform interactiveTranslateTransform = new TranslateTransform();       
            this.RegisterName("InteractiveTranslateTransform", interactiveTranslateTransform);
            
            interactiveEllipse.RenderTransform = 
                interactiveTranslateTransform;
                
            xAnimation = new DoubleAnimation();
            xAnimation.Duration = TimeSpan.FromSeconds(4);
            yAnimation = xAnimation.Clone();
            Storyboard.SetTargetName(xAnimation, "InteractiveTranslateTransform");
            Storyboard.SetTargetProperty(xAnimation, new PropertyPath(TranslateTransform.XProperty));
            Storyboard.SetTargetName(yAnimation, "InteractiveTranslateTransform");
            Storyboard.SetTargetProperty(yAnimation, new PropertyPath(TranslateTransform.YProperty));            
            
            theStoryboard = new Storyboard();
            theStoryboard.Children.Add(xAnimation);
            theStoryboard.Children.Add(yAnimation);

            containerBorder.MouseLeftButtonDown += 
                new MouseButtonEventHandler(border_mouseLeftButtonDown);
            containerBorder.MouseRightButtonDown += 
                new MouseButtonEventHandler(border_mouseRightButtonDown);                
            
            containerBorder.Child = interactiveEllipse;
            myPanel.Children.Add(containerBorder);
            this.Content = myPanel;
        }

        // When the user left-clicks, use the 
        // SnapshotAndReplace HandoffBehavior when applying the animation.        
        private void border_mouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
        
            Point clickPoint = Mouse.GetPosition(containerBorder);
            
            // Set the target point so the center of the ellipse
            // ends up at the clicked point.
            Point targetPoint = new Point();
            targetPoint.X = clickPoint.X - interactiveEllipse.Width / 2;
            targetPoint.Y = clickPoint.Y - interactiveEllipse.Height / 2;  
            
            // Animate to the target point.
            xAnimation.To = targetPoint.X;
            yAnimation.To = targetPoint.Y;
            theStoryboard.Begin(this, HandoffBehavior.SnapshotAndReplace);

            // Change the color of the ellipse.
            interactiveEllipse.Fill = Brushes.Lime;
        }
        
        // When the user right-clicks, use the 
        // Compose HandoffBehavior when applying the animation.
        private void border_mouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
        
            // Find the point where the use clicked.
            Point clickPoint = Mouse.GetPosition(containerBorder);
            
            // Set the target point so the center of the ellipse
            // ends up at the clicked point.
            Point targetPoint = new Point();
            targetPoint.X = clickPoint.X - interactiveEllipse.Width / 2;
            targetPoint.Y = clickPoint.Y - interactiveEllipse.Height / 2;
 
            // Animate to the target point.
            xAnimation.To = targetPoint.X;
            yAnimation.To = targetPoint.Y;
            theStoryboard.Begin(this, HandoffBehavior.Compose);
                
            // Change the color of the ellipse.
            interactiveEllipse.Fill = Brushes.Orange;
        }
    }
}

Se aplica a

.NET Framework 4.8.1 y otras versiones
Producto Versiones
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Begin(FrameworkContentElement, HandoffBehavior)

Aplica las animaciones asociadas a este Storyboard a sus destinos e inicia, utilizando el HandoffBehaviorespecificado.

C#
public void Begin (System.Windows.FrameworkContentElement containingObject, System.Windows.Media.Animation.HandoffBehavior handoffBehavior);

Parámetros

containingObject
FrameworkContentElement

Objeto contenido en el mismo ámbito de nombre que los destinos de las animaciones de este guión gráfico. Las animaciones sin un TargetName se aplican a containingObject.

handoffBehavior
HandoffBehavior

El comportamiento que debe usar la nueva animación para interactuar con las animaciones actuales.

Ejemplos

En el ejemplo siguiente se usa el SnapshotAndReplaceHandoffBehavior para animar cuando el usuario hace clic con el botón izquierdo y el ComposeHandoffBehavior cuando el usuario hace clic con el botón derecho.

C#
/*
    This example shows how to animate
    a FrameworkContentElement with a storyboard.

*/

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Windows.Documents;
using System.Windows.Input;

namespace Microsoft.Samples.Animation.AnimatingWithStoryboards
{
    public class FrameworkContentElementStoryboardWithHandoffBehaviorExample : 
        FlowDocument
    {
    
        private Storyboard myStoryboard;
        DoubleAnimation xAnimation;
        DoubleAnimation yAnimation;
        
        public FrameworkContentElementStoryboardWithHandoffBehaviorExample()
        {
        
            // Create a name scope for the document.
            NameScope.SetNameScope(this, new NameScope());        
            this.Background = Brushes.Orange;
            
            // Create a run of text.
            Run theText = new Run( 
                "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.");   
                
            // Create a TextEffect
            TextEffect animatedSpecialEffect = new TextEffect();
            animatedSpecialEffect.Foreground = Brushes.OrangeRed;
            animatedSpecialEffect.PositionStart = 0;
            animatedSpecialEffect.PositionCount = 20;
            
            TranslateTransform animatedTransform = 
                new TranslateTransform();
                
            // Assign the transform a name by 
            // registering it with the page, so that
            // it can be targeted by storyboard
            // animations.      
            this.RegisterName("animatedTransform", animatedTransform);             
            animatedSpecialEffect.Transform = animatedTransform;

            // Apply the text effect to the run.
            theText.TextEffects = new TextEffectCollection();
            theText.TextEffects.Add(animatedSpecialEffect);

            // Create a paragraph to contain the run.
            Paragraph animatedParagraph = new Paragraph(theText);
            animatedParagraph.Background = Brushes.LightGray;           
   
            this.Blocks.Add(animatedParagraph);                           
            
            //
            // Create a storyboard to animate the
            // text effect's transform.
            //
            myStoryboard = new Storyboard();
            
            xAnimation = new DoubleAnimation();  
            xAnimation.Duration = TimeSpan.FromSeconds(5);                        
            Storyboard.SetTargetName(xAnimation, "animatedTransform");
            Storyboard.SetTargetProperty(xAnimation, 
                new PropertyPath(TranslateTransform.XProperty));      
            myStoryboard.Children.Add(xAnimation);
            
            yAnimation = new DoubleAnimation();
            yAnimation.Duration = TimeSpan.FromSeconds(5);           
            Storyboard.SetTargetName(yAnimation, "animatedTransform");
            Storyboard.SetTargetProperty(yAnimation, 
                new PropertyPath(TranslateTransform.YProperty));      
            myStoryboard.Children.Add(yAnimation);            
            
            this.MouseLeftButtonDown += 
                new MouseButtonEventHandler(document_mouseLeftButtonDown);
            this.MouseRightButtonDown += 
                new MouseButtonEventHandler(document_mouseRightButtonDown);
        }

        // When the user left-clicks, use the 
        // SnapshotAndReplace HandoffBehavior when applying the animation.        
        private void document_mouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
        
            Point clickPoint = Mouse.GetPosition(this);

            // Animate to the target point.
            xAnimation.To = clickPoint.X; 
            yAnimation.To = clickPoint.Y;

            try
            {
                myStoryboard.Begin(this, HandoffBehavior.SnapshotAndReplace);  
            }catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        
        // When the user right-clicks, use the 
        // Compose HandoffBehavior when applying the animation.
        private void document_mouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {

            Point clickPoint = Mouse.GetPosition(this);

            // Animate to the target point.
            xAnimation.To = clickPoint.X;
            yAnimation.To = clickPoint.Y;
            myStoryboard.Begin(this, HandoffBehavior.Compose);  
        }        
    }
}

Comentarios

Cuando se aplica un Storyboard, AnimationTimelineo AnimationClock a una propiedad mediante el ComposeHandoffBehavior, los objetos Clock asociados previamente a esa propiedad siguen usando recursos del sistema; el sistema de control de tiempo no quita automáticamente estos relojes.

Para evitar problemas de rendimiento al aplicar un gran número de relojes mediante Compose, debe quitar la composición de los relojes de la propiedad animada después de completarlos. Hay varias maneras de quitar un reloj.

Esto es principalmente un problema para animaciones en objetos que tienen una larga duración. Cuando se recopila un objeto, sus relojes también se desconectan y se recopilan elementos no utilizados.

Para obtener más información sobre los objetos de reloj, vea Animation and Timing System Overview.

Se aplica a

.NET Framework 4.8.1 y otras versiones
Producto Versiones
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Begin(FrameworkContentElement, Boolean)

Aplica las animaciones asociadas a este Storyboard a sus destinos y las inicia.

C#
public void Begin (System.Windows.FrameworkContentElement containingObject, bool isControllable);

Parámetros

containingObject
FrameworkContentElement

Objeto contenido en el mismo ámbito de nombre que los destinos de las animaciones de este guión gráfico. Las animaciones sin un TargetName se aplican a containingObject.

isControllable
Boolean

true si el guión gráfico debe controlarse de forma interactiva; de lo contrario, false.

Ejemplos

En el ejemplo siguiente se usa un guión gráfico controlable para animar un TextEffect. El TextEffect se encuentra dentro de un ámbito de nombre de FrameworkContentElement.

C#
/*
    This example shows how to control
    a storyboard after it has started.

*/

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Windows.Documents;

namespace Microsoft.Samples.Animation.AnimatingWithStoryboards
{
    public class FrameworkContentElementControlStoryboardExample : FlowDocument
    {
    
        private Storyboard myStoryboard;
        
        public FrameworkContentElementControlStoryboardExample()
        {
        
            // Create a name scope for the document.
            NameScope.SetNameScope(this, new NameScope());        
            this.Background = Brushes.White;
            
            // Create a run of text.
            Run theText = new Run( 
                "Lorem ipsum dolor sit amet, consectetuer adipiscing elit." + 
                "Ut non lacus. Nullam a ligula id leo adipiscing ornare." +
                " Duis mattis. ");   
                
            // Create a TextEffect
            TextEffect animatedSpecialEffect = new TextEffect();
            animatedSpecialEffect.Foreground = Brushes.OrangeRed;
            animatedSpecialEffect.PositionStart = 0;
            animatedSpecialEffect.PositionCount = 0;
            
            // Assign the TextEffect a name by 
            // registering it with the page, so that
            // it can be targeted by storyboard
            // animations            
            this.RegisterName("animatedSpecialEffect", animatedSpecialEffect);  
            
            // Apply the text effect to the run.
            theText.TextEffects = new TextEffectCollection();
            theText.TextEffects.Add(animatedSpecialEffect);
            
            // Create a paragraph to contain the run.
            Paragraph animatedParagraph = new Paragraph(theText);
            animatedParagraph.Background = Brushes.LightGray;
            animatedParagraph.Padding = new Thickness(20);
   
            this.Blocks.Add(animatedParagraph);            
            BlockUIContainer controlsContainer = new BlockUIContainer();                
            
            //
            // Create an animation and a storyboard to animate the
            // text effect.
            //
            Int32Animation countAnimation = 
                new Int32Animation(0, 127, TimeSpan.FromSeconds(10)); 
            Storyboard.SetTargetName(countAnimation, "animatedSpecialEffect");
            Storyboard.SetTargetProperty(countAnimation, 
                new PropertyPath(TextEffect.PositionCountProperty));
            myStoryboard = new Storyboard();
            myStoryboard.Children.Add(countAnimation);
            
            //
            // Create some buttons to control the storyboard
            // and a panel to contain them.
            //
            StackPanel buttonPanel = new StackPanel();
            buttonPanel.Orientation = Orientation.Vertical;
            Button beginButton = new Button();
            beginButton.Content = "Begin";
            beginButton.Click += new RoutedEventHandler(beginButton_Clicked);            
            buttonPanel.Children.Add(beginButton);
            Button pauseButton = new Button();
            pauseButton.Content = "Pause";
            pauseButton.Click +=new RoutedEventHandler(pauseButton_Clicked);
            buttonPanel.Children.Add(pauseButton);
            Button resumeButton = new Button();
            resumeButton.Content = "Resume";
            resumeButton.Click +=new RoutedEventHandler(resumeButton_Clicked);
            buttonPanel.Children.Add(resumeButton);
            Button skipToFillButton = new Button();
            skipToFillButton.Content = "Skip to Fill";
            skipToFillButton.Click +=new RoutedEventHandler(skipToFillButton_Clicked);
            buttonPanel.Children.Add(skipToFillButton);
            Button setSpeedRatioButton = new Button();
            setSpeedRatioButton.Content = "Triple Speed";
            setSpeedRatioButton.Click +=new RoutedEventHandler(setSpeedRatioButton_Clicked);
            buttonPanel.Children.Add(setSpeedRatioButton);
            Button stopButton = new Button();
            stopButton.Content = "Stop";
            stopButton.Click +=new RoutedEventHandler(stopButton_Clicked);
            buttonPanel.Children.Add(stopButton);
            Button removeButton = new Button();
            removeButton.Content = "Remove";
            removeButton.Click +=new RoutedEventHandler(removeButton_Clicked);
            buttonPanel.Children.Add(removeButton); 
   
            controlsContainer.Child = buttonPanel; 
            this.Blocks.Add(controlsContainer);
        }
        
        // Begins the storyboard.
        private void beginButton_Clicked(object sender, RoutedEventArgs args)
        {
            // Specifying "true" as the second Begin parameter
            // makes this storyboard controllable.
            myStoryboard.Begin(this, true);          
        }
        
        // Pauses the storyboard.
        private void pauseButton_Clicked(object sender, RoutedEventArgs args)
        {
             myStoryboard.Pause(this);          
        }
        
        // Resumes the storyboard.
        private void resumeButton_Clicked(object sender, RoutedEventArgs args)
        {
             myStoryboard.Resume(this);          
        }     
        
        // Advances the storyboard to its fill period.
        private void skipToFillButton_Clicked(object sender, RoutedEventArgs args)
        {
             myStoryboard.SkipToFill(this);          
        } 
        
        // Updates the storyboard's speed.
        private void setSpeedRatioButton_Clicked(object sender, RoutedEventArgs args)
        {
            // Makes the storyboard progress three times as fast as normal.
            myStoryboard.SetSpeedRatio(this, 3);          
        }           
        
        // Stops the storyboard.
        private void stopButton_Clicked(object sender, RoutedEventArgs args)
        {
             myStoryboard.Stop(this);          
        }     
        
        // Removes the storyboard.
        private void removeButton_Clicked(object sender, RoutedEventArgs args)
        {
             myStoryboard.Remove(this);          
        }           
    }
}

Comentarios

Si las propiedades de destino ya están animadas, se reemplazan mediante el comportamiento de entrega SnapshotAndReplace.

Para controlar interactivamente este guión gráfico, debe especificar el mismo containingObject al llamar a los métodos interactivos que usó para comenzar el guión gráfico.

Cuando se llama a este método, se crean Clock objetos para el guión gráfico y las escalas de tiempo que contiene. Estos relojes se almacenan con containingObject.

Al iniciar un guión gráfico, se desencadenan los eventos CurrentStateInvalidated y CurrentGlobalSpeedInvalidated.

Se aplica a

.NET Framework 4.8.1 y otras versiones
Producto Versiones
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Begin(FrameworkElement)

Aplica las animaciones asociadas a este Storyboard a sus destinos y las inicia.

C#
public void Begin (System.Windows.FrameworkElement containingObject);

Parámetros

containingObject
FrameworkElement

Objeto contenido en el mismo ámbito de nombre que los destinos de las animaciones de este guión gráfico. Las animaciones sin un TargetName se aplican a containingObject.

Comentarios

Si las propiedades de destino ya están animadas, se reemplazan mediante el comportamiento de entrega SnapshotAndReplace.

Los guiones gráficos iniciados con este método no se pueden pausar, reanudar ni controlar interactivamente una vez iniciados. Para que un guión gráfico pueda controlarse, use el método Begin(FrameworkElement, Boolean) o Begin(FrameworkElement, HandoffBehavior, Boolean).

Al iniciar un guión gráfico, se desencadenan los eventos CurrentStateInvalidated y CurrentGlobalSpeedInvalidated.

Se aplica a

.NET Framework 4.8.1 y otras versiones
Producto Versiones
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Begin(FrameworkContentElement)

Aplica las animaciones asociadas a este Storyboard a sus destinos y las inicia.

C#
public void Begin (System.Windows.FrameworkContentElement containingObject);

Parámetros

containingObject
FrameworkContentElement

Objeto contenido en el mismo ámbito de nombre que los destinos de las animaciones de este guión gráfico. Las animaciones sin un TargetName se aplican a containingObject.

Ejemplos

En el ejemplo siguiente se usa un guión gráfico para animar un TextEffect. El TextEffect se encuentra dentro de un ámbito de nombre de FrameworkContentElement.

C#
/*
    This example shows how to animate
    a FrameworkContentElement with a storyboard.

*/

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Windows.Documents;

namespace Microsoft.Samples.Animation.AnimatingWithStoryboards
{
    public class FrameworkContentElementStoryboardExample : FlowDocument
    {
    
        private Storyboard myStoryboard;
        
        public FrameworkContentElementStoryboardExample()
        {
        
            // Create a name scope for the document.
            NameScope.SetNameScope(this, new NameScope());        
            this.Background = Brushes.White;
            
            // Create a run of text.
            Run theText = new Run( 
                "Lorem ipsum dolor sit amet, consectetuer adipiscing elit." + 
                "Ut non lacus. Nullam a ligula id leo adipiscing ornare." +
                " Duis mattis. ");   
                
            // Create a TextEffect
            TextEffect animatedSpecialEffect = new TextEffect();
            animatedSpecialEffect.Foreground = Brushes.OrangeRed;
            animatedSpecialEffect.PositionStart = 0;
            animatedSpecialEffect.PositionCount = 0;
            
            // Assign the TextEffect a name by 
            // registering it with the page, so that
            // it can be targeted by storyboard
            // animations            
            this.RegisterName("animatedSpecialEffect", animatedSpecialEffect);  
            
            // Apply the text effect to the run.
            theText.TextEffects = new TextEffectCollection();
            theText.TextEffects.Add(animatedSpecialEffect);
            
            // Create a paragraph to contain the run.
            Paragraph animatedParagraph = new Paragraph(theText);
            animatedParagraph.Background = Brushes.LightGray;
            animatedParagraph.Padding = new Thickness(20);
   
            this.Blocks.Add(animatedParagraph);            
            BlockUIContainer controlsContainer = new BlockUIContainer();                
            
            //
            // Create an animation and a storyboard to animate the
            // text effect.
            //
            Int32Animation countAnimation = 
                new Int32Animation(0, 127, TimeSpan.FromSeconds(10));            
            Storyboard.SetTargetName(countAnimation, "animatedSpecialEffect");
            Storyboard.SetTargetProperty(countAnimation, 
                new PropertyPath(TextEffect.PositionCountProperty));
            myStoryboard = new Storyboard();
            myStoryboard.Children.Add(countAnimation);
            
            //
            // Create a button to start the storyboard.
            //
            Button beginButton = new Button();
            beginButton.Content = "Begin";
            beginButton.Click += new RoutedEventHandler(beginButton_Clicked);            
 
            controlsContainer.Child = beginButton; 
            this.Blocks.Add(controlsContainer);
        }
        
        // Begins the storyboard.
        private void beginButton_Clicked(object sender, RoutedEventArgs args)
        {
        
            myStoryboard.Begin(this);                  
        }
    }
}

Comentarios

Si las propiedades de destino ya están animadas, se reemplazan mediante el comportamiento de entrega SnapshotAndReplace.

Los guiones gráficos iniciados con este método no se pueden pausar, reanudar ni controlar interactivamente una vez iniciados. Para que un guión gráfico pueda controlarse, use el método Begin o Begin.

Al iniciar un guión gráfico, se desencadenan los eventos CurrentStateInvalidated y CurrentGlobalSpeedInvalidated.

Se aplica a

.NET Framework 4.8.1 y otras versiones
Producto Versiones
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Begin()

Aplica las animaciones asociadas a este Storyboard a sus destinos y las inicia.

C#
public void Begin ();

Se aplica a

.NET Framework 4.8.1 y otras versiones
Producto Versiones
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Begin(FrameworkElement, Boolean)

Aplica las animaciones asociadas a este Storyboard a sus destinos y las inicia.

C#
public void Begin (System.Windows.FrameworkElement containingObject, bool isControllable);

Parámetros

containingObject
FrameworkElement

Objeto contenido en el mismo ámbito de nombre que los destinos de las animaciones de este guión gráfico. Las animaciones sin un TargetName se aplican a containingObject.

isControllable
Boolean

true si el guión gráfico debe controlarse de forma interactiva; de lo contrario, false.

Comentarios

Si las propiedades de destino ya están animadas, se reemplazan mediante el comportamiento de entrega SnapshotAndReplace.

Para controlar interactivamente este guión gráfico, debe usar el mismo parámetro containingObject al llamar a los métodos interactivos que usó para comenzar el guión gráfico.

Cuando se llama a este método, se crean Clock objetos para el guión gráfico y las escalas de tiempo que contiene. Estos relojes se almacenan con containingObject.

Al iniciar un guión gráfico, se desencadenan los eventos CurrentStateInvalidated y CurrentGlobalSpeedInvalidated.

Se aplica a

.NET Framework 4.8.1 y otras versiones
Producto Versiones
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9