Exportar (0) Imprimir
Expandir todo

Storyboard.Begin (Método) (FrameworkElement, HandoffBehavior)

Actualización: noviembre 2007

Aplica las animaciones asociadas con este objeto Storyboard a sus destinos y las inicia utilizando la enumeración HandoffBehavior especificada.

Espacio de nombres:  System.Windows.Media.Animation
Ensamblado:  PresentationFramework (en PresentationFramework.dll)

public void Begin(
	FrameworkElement containingObject,
	HandoffBehavior handoffBehavior
)
public void Begin(
	FrameworkElement containingObject,
	HandoffBehavior handoffBehavior
)
public function Begin(
	containingObject : FrameworkElement, 
	handoffBehavior : HandoffBehavior
)
No se pueden utilizar métodos en XAML.

Parámetros

containingObject
Tipo: System.Windows.FrameworkElement
Objeto que pertenece al mismo ámbito de nombres que los destinos de las animaciones del guión gráfico. Las animaciones en las que no se ha especificado TargetName se aplican a containingObject.
handoffBehavior
Tipo: System.Windows.Media.Animation.HandoffBehavior
Comportamiento que la nueva animación debe utilizar para interactuar con las animaciones actuales.

En el siguiente ejemplo se utiliza el campo SnapshotAndReplace de HandoffBehavior para aplicar la animación cuando el usuario hace clic con el botón primario del mouse y se utiliza el campo Compose de HandoffBehavior cuando el usuario hace clic con el botón secundario del mouse.

/*

   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;


        }

    }

}


Windows Vista

.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.

.NET Framework

Compatible con: 3.5, 3.0

Adiciones de comunidad

AGREGAR
Mostrar:
© 2015 Microsoft