Animatable.BeginAnimation メソッド
定義
指定された DependencyProperty にアニメーションを適用します。Applies an animation to the specified DependencyProperty.
オーバーロード
BeginAnimation(DependencyProperty, AnimationTimeline) |
指定された DependencyProperty にアニメーションを適用します。Applies an animation to the specified DependencyProperty. アニメーションは、次のフレームがレンダリングされるときに開始されます。The animation is started when the next frame is rendered. 指定されたプロパティが既にアニメーション化されている場合は、SnapshotAndReplace ハンドオフ動作が使用されます。If the specified property is already animated, the SnapshotAndReplace handoff behavior is used. |
BeginAnimation(DependencyProperty, AnimationTimeline, HandoffBehavior) |
指定された DependencyProperty にアニメーションを適用します。Applies an animation to the specified DependencyProperty. アニメーションは、次のフレームがレンダリングされるときに開始されます。The animation is started when the next frame is rendered. 指定したプロパティが既にアニメーション化されている場合は、指定した HandoffBehavior が使用されます。If the specified property is already animated, the specified HandoffBehavior is used. |
BeginAnimation(DependencyProperty, AnimationTimeline)
指定された DependencyProperty にアニメーションを適用します。Applies an animation to the specified DependencyProperty. アニメーションは、次のフレームがレンダリングされるときに開始されます。The animation is started when the next frame is rendered. 指定されたプロパティが既にアニメーション化されている場合は、SnapshotAndReplace ハンドオフ動作が使用されます。If the specified property is already animated, the SnapshotAndReplace handoff behavior is used.
public:
virtual void BeginAnimation(System::Windows::DependencyProperty ^ dp, System::Windows::Media::Animation::AnimationTimeline ^ animation);
public void BeginAnimation (System.Windows.DependencyProperty dp, System.Windows.Media.Animation.AnimationTimeline animation);
abstract member BeginAnimation : System.Windows.DependencyProperty * System.Windows.Media.Animation.AnimationTimeline -> unit
override this.BeginAnimation : System.Windows.DependencyProperty * System.Windows.Media.Animation.AnimationTimeline -> unit
Public Sub BeginAnimation (dp As DependencyProperty, animation As AnimationTimeline)
パラメーター
アニメーション化するプロパティ。The property to animate.
- animation
- AnimationTimeline
指定したプロパティをアニメーション化するために使用するアニメーション。The animation used to animate the specified property.
アニメーションの BeginTime が null
の場合、現在のアニメーションは削除され、プロパティの現在の値は保持されます。If the animation's BeginTime is null
, any current animations will be removed and the current value of the property will be held.
animation
が null
の場合、すべてのアニメーションがプロパティから削除され、プロパティの値は、その基本値に戻ります。If animation
is null
, all animations will be removed from the property and the property value will revert back to its base value.
実装
注釈
アニメーションBeginTimeのが0より大きい場合、アニメーションは次のフレームがレンダリングされてから経過した後に開始します。If the animation has a BeginTime that is greater than zero, the animation begins after that amount of time has elapsed from the time the next frame is rendered.
BeginAnimation(DependencyProperty, AnimationTimeline, HandoffBehavior)
指定された DependencyProperty にアニメーションを適用します。Applies an animation to the specified DependencyProperty. アニメーションは、次のフレームがレンダリングされるときに開始されます。The animation is started when the next frame is rendered. 指定したプロパティが既にアニメーション化されている場合は、指定した HandoffBehavior が使用されます。If the specified property is already animated, the specified HandoffBehavior is used.
public:
virtual void BeginAnimation(System::Windows::DependencyProperty ^ dp, System::Windows::Media::Animation::AnimationTimeline ^ animation, System::Windows::Media::Animation::HandoffBehavior handoffBehavior);
public void BeginAnimation (System.Windows.DependencyProperty dp, System.Windows.Media.Animation.AnimationTimeline animation, System.Windows.Media.Animation.HandoffBehavior handoffBehavior);
abstract member BeginAnimation : System.Windows.DependencyProperty * System.Windows.Media.Animation.AnimationTimeline * System.Windows.Media.Animation.HandoffBehavior -> unit
override this.BeginAnimation : System.Windows.DependencyProperty * System.Windows.Media.Animation.AnimationTimeline * System.Windows.Media.Animation.HandoffBehavior -> unit
パラメーター
アニメーション化するプロパティ。The property to animate.
- animation
- AnimationTimeline
指定したプロパティをアニメーション化するために使用するアニメーション。The animation used to animate the specified property.
handoffBehavior
が SnapshotAndReplace であり、アニメーションの BeginTime が null
である場合、現在のアニメーションはすべて削除され、プロパティの現在の値が保持されます。If handoffBehavior
is SnapshotAndReplace and the animation's BeginTime is null
, any current animations will be removed and the current value of the property will be held.
handoffBehavior
が SnapshotAndReplace であり、animation
が null
参照である場合、すべてのアニメーションがプロパティから削除され、プロパティ値が基本値に戻ります。If handoffBehavior
is SnapshotAndReplace and animation
is a null
reference, all animations will be removed from the property and the property value will revert back to its base value.
handoffBehavior
が Compose であっても、アニメーションまたはその BeginTime が null
である場合は、このメソッドは無効です。If handoffBehavior
is Compose, this method will have no effect if the animation or its BeginTime is null
.
- handoffBehavior
- HandoffBehavior
プロパティ値に既に影響を及ぼしている現在のアニメーションと新しいアニメーションが対話する方法を指定する値。A value that specifies how the new animation should interact with any current animations already affecting the property value.
実装
例
次の例では、さまざまなHandoffBehavior設定を使用してアニメーションを適用する方法を示します。The following example shows how to apply animations using different HandoffBehavior settings.
/*
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 namespace System;
using namespace System::Windows;
using namespace System::Windows::Navigation;
using namespace System::Windows::Media;
using namespace System::Windows::Media::Animation;
using namespace System::Windows::Shapes;
using namespace System::Windows::Controls;
using namespace System::Windows::Input;
namespace Microsoft {
namespace Samples {
namespace Animation {
namespace LocalAnimations {
public ref class InteractiveAnimationExample : Page {
private:
TranslateTransform^ interactiveTranslateTransform;
Border^ containerBorder;
Ellipse^ interactiveEllipse;
public:
InteractiveAnimationExample ()
{
WindowTitle = "Interactive Animation Example";
DockPanel^ myPanel = gcnew DockPanel();
myPanel->Margin = Thickness(20.0);
containerBorder = gcnew Border();
containerBorder->Background = Brushes::White;
containerBorder->BorderBrush = Brushes::Black;
containerBorder->BorderThickness = Thickness(2.0);
containerBorder->VerticalAlignment = System::Windows::VerticalAlignment::Stretch;
interactiveEllipse = gcnew Ellipse();
interactiveEllipse->Fill = Brushes::Lime;
interactiveEllipse->Stroke = Brushes::Black;
interactiveEllipse->StrokeThickness = 2.0;
interactiveEllipse->Width = 25;
interactiveEllipse->Height = 25;
interactiveEllipse->HorizontalAlignment = System::Windows::HorizontalAlignment::Left;
interactiveEllipse->VerticalAlignment = System::Windows::VerticalAlignment::Top;
interactiveTranslateTransform = gcnew TranslateTransform();
interactiveEllipse->RenderTransform = interactiveTranslateTransform;
containerBorder->MouseLeftButtonDown +=
gcnew MouseButtonEventHandler(this, &Microsoft::Samples::Animation::LocalAnimations::InteractiveAnimationExample::border_mouseLeftButtonDown);
containerBorder->MouseRightButtonDown +=
gcnew MouseButtonEventHandler(this, &Microsoft::Samples::Animation::LocalAnimations::InteractiveAnimationExample::border_mouseRightButtonDown);
containerBorder->Child = interactiveEllipse;
myPanel->Children->Add(containerBorder);
this->Content = myPanel;
};
private:
// When the user left-clicks, use the
// SnapshotAndReplace HandoffBehavior when applying the animation.
void border_mouseLeftButtonDown (System::Object^ sender, System::Windows::Input::MouseButtonEventArgs^ e)
{
System::Windows::Point clickPoint = Mouse::GetPosition(containerBorder);
// Set the target point so the center of the ellipse
// ends up at the clicked point.
Point targetPoint = Point();
targetPoint.X = clickPoint.X - interactiveEllipse->Width / 2;
targetPoint.Y = clickPoint.Y - interactiveEllipse->Height / 2;
// Animate to the target point.
DoubleAnimation^ xAnimation = gcnew DoubleAnimation(targetPoint.X,
Duration(TimeSpan::FromSeconds(4)));
interactiveTranslateTransform->BeginAnimation(TranslateTransform::XProperty, xAnimation, HandoffBehavior::SnapshotAndReplace);
DoubleAnimation^ yAnimation = gcnew DoubleAnimation(targetPoint.Y,
Duration(TimeSpan::FromSeconds(4)));
interactiveTranslateTransform->BeginAnimation(TranslateTransform::YProperty, yAnimation, HandoffBehavior::SnapshotAndReplace);
// Chage the color of the ellipse.
interactiveEllipse->Fill = Brushes::Lime;
}
private:
// When the user right-clicks, use the
// Compose HandoffBehavior when applying the animation.
void border_mouseRightButtonDown (System::Object^ sender, System::Windows::Input::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 = System::Windows::Point();
targetPoint.X = clickPoint.X - interactiveEllipse->Width / 2;
targetPoint.Y = clickPoint.Y - interactiveEllipse->Height / 2;
// Animate to the target point.
DoubleAnimation^ xAnimation = gcnew DoubleAnimation(targetPoint.X,
Duration(TimeSpan::FromSeconds(4)));
interactiveTranslateTransform->BeginAnimation(TranslateTransform::XProperty, xAnimation, HandoffBehavior::Compose);
DoubleAnimation^ yAnimation = gcnew DoubleAnimation(targetPoint.Y,
Duration(TimeSpan::FromSeconds(4)));
// Change the color of the ellipse.
interactiveTranslateTransform->BeginAnimation(TranslateTransform::YProperty, yAnimation, HandoffBehavior::Compose);
interactiveEllipse->Fill = Brushes::Orange;
}
};
}
}
}
}
/*
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.LocalAnimations
{
// Create the demonstration.
public class InteractiveAnimationExample : Page {
private TranslateTransform interactiveTranslateTransform;
private Border containerBorder;
private Ellipse interactiveEllipse;
public InteractiveAnimationExample()
{
WindowTitle = "Interactive Animation Example";
DockPanel myPanel = new DockPanel();
myPanel.Margin = new Thickness(20.0);
containerBorder = new Border();
containerBorder.Background = System.Windows.Media.Brushes.White;
containerBorder.BorderBrush = System.Windows.Media.Brushes.Black;
containerBorder.BorderThickness = new Thickness(2.0);
containerBorder.VerticalAlignment = VerticalAlignment.Stretch;
interactiveEllipse = new Ellipse();
interactiveEllipse.Fill = System.Windows.Media.Brushes.Lime;
interactiveEllipse.Stroke = System.Windows.Media.Brushes.Black;
interactiveEllipse.StrokeThickness = 2.0;
interactiveEllipse.Width = 25;
interactiveEllipse.Height = 25;
interactiveEllipse.HorizontalAlignment = HorizontalAlignment.Left;
interactiveEllipse.VerticalAlignment = VerticalAlignment.Top;
interactiveTranslateTransform = new TranslateTransform();
interactiveEllipse.RenderTransform =
interactiveTranslateTransform;
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)
{
System.Windows.Point clickPoint = Mouse.GetPosition(containerBorder);
// Set the target point so the center of the ellipse
// ends up at the clicked point.
System.Windows.Point targetPoint = new System.Windows.Point();
targetPoint.X = clickPoint.X - interactiveEllipse.Width / 2;
targetPoint.Y = clickPoint.Y - interactiveEllipse.Height / 2;
// Animate to the target point.
DoubleAnimation xAnimation =
new DoubleAnimation(targetPoint.X,
new Duration(TimeSpan.FromSeconds(4)));
interactiveTranslateTransform.BeginAnimation(
TranslateTransform.XProperty, xAnimation, HandoffBehavior.SnapshotAndReplace);
DoubleAnimation yAnimation =
new DoubleAnimation(targetPoint.Y,
new Duration(TimeSpan.FromSeconds(4)));
interactiveTranslateTransform.BeginAnimation(
TranslateTransform.YProperty, yAnimation, HandoffBehavior.SnapshotAndReplace);
// Change the color of the ellipse.
interactiveEllipse.Fill = System.Windows.Media.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.
System.Windows.Point clickPoint = Mouse.GetPosition(containerBorder);
// Set the target point so the center of the ellipse
// ends up at the clicked point.
System.Windows.Point targetPoint = new System.Windows.Point();
targetPoint.X = clickPoint.X - interactiveEllipse.Width / 2;
targetPoint.Y = clickPoint.Y - interactiveEllipse.Height / 2;
// Animate to the target point.
DoubleAnimation xAnimation =
new DoubleAnimation(targetPoint.X,
new Duration(TimeSpan.FromSeconds(4)));
interactiveTranslateTransform.BeginAnimation(
TranslateTransform.XProperty, xAnimation, HandoffBehavior.Compose);
DoubleAnimation yAnimation =
new DoubleAnimation(targetPoint.Y,
new Duration(TimeSpan.FromSeconds(4)));
interactiveTranslateTransform.BeginAnimation(
TranslateTransform.YProperty, yAnimation, HandoffBehavior.Compose);
// Change the color of the ellipse.
interactiveEllipse.Fill = System.Windows.Media.Brushes.Orange;
}
}
}
'
'
' 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.
'
'
Imports System.Windows
Imports System.Windows.Navigation
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes
Imports System.Windows.Controls
Imports System.Windows.Input
Namespace Microsoft.Samples.Animation.LocalAnimations
' Create the demonstration.
Public Class InteractiveAnimationExample
Inherits Page
Private Dim interactiveTranslateTransform As TranslateTransform
Private Dim WithEvents containerBorder As Border
Private Dim interactiveEllipse As Ellipse
Public Sub New()
WindowTitle = "Interactive Animation Example"
Dim myPanel As 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
interactiveTranslateTransform = new TranslateTransform()
interactiveEllipse.RenderTransform = _
interactiveTranslateTransform
containerBorder.Child = interactiveEllipse
myPanel.Children.Add(containerBorder)
Me.Content = myPanel
End Sub
' When the user left-clicks, use the
' SnapshotAndReplace HandoffBehavior when applying the animation.
Private Sub border_mouseLeftButtonDown( _
ByVal sender As Object, ByVal e As MouseButtonEventArgs) _
Handles containerBorder.MouseLeftButtonDown
Dim clickPoint = Mouse.GetPosition(containerBorder)
' Set the target point so the center of the ellipse
' ends up at the clicked point.
Dim targetPoint As New System.Windows.Point()
targetPoint.X = clickPoint.X - interactiveEllipse.Width / 2
targetPoint.Y = clickPoint.Y - interactiveEllipse.Height / 2
' Animate to the target point.
Dim xAnimation As _
New DoubleAnimation(targetPoint.X, _
New Duration(TimeSpan.FromSeconds(4)))
interactiveTranslateTransform.BeginAnimation( _
TranslateTransform.XProperty, xAnimation, HandoffBehavior.SnapshotAndReplace)
Dim yAnimation As _
New DoubleAnimation(targetPoint.Y, _
New Duration(TimeSpan.FromSeconds(4)))
interactiveTranslateTransform.BeginAnimation( _
TranslateTransform.YProperty, yAnimation, HandoffBehavior.SnapshotAndReplace)
' Change the color of the ellipse.
interactiveEllipse.Fill = Brushes.Lime
End Sub
' When the user right-clicks, use the
' Compose HandoffBehavior when applying the animation.
Private Sub border_mouseRightButtonDown( _
ByVal sender As Object, ByVal e As MouseButtonEventArgs) _
Handles containerBorder.MouseRightButtonDown
' Find the point where the use clicked.
Dim clickPoint = Mouse.GetPosition(containerBorder)
' Set the target point so the center of the ellipse
' ends up at the clicked point.
Dim targetPoint As New System.Windows.Point()
targetPoint.X = clickPoint.X - interactiveEllipse.Width / 2
targetPoint.Y = clickPoint.Y - interactiveEllipse.Height / 2
' Animate to the target point.
Dim xAnimation As _
New DoubleAnimation(targetPoint.X, _
New Duration(TimeSpan.FromSeconds(4)))
interactiveTranslateTransform.BeginAnimation( _
TranslateTransform.XProperty, xAnimation, HandoffBehavior.Compose)
Dim yAnimation As _
New DoubleAnimation(targetPoint.Y, _
New Duration(TimeSpan.FromSeconds(4)))
interactiveTranslateTransform.BeginAnimation( _
TranslateTransform.YProperty, yAnimation, HandoffBehavior.Compose)
' Change the color of the ellipse.
interactiveEllipse.Fill = Brushes.Orange
End Sub
End Class
End Namespace
注釈
アニメーションBeginTimeのが0より大きい場合、アニメーションは次のフレームがレンダリングされてから経過した後に開始します。If the animation has a BeginTime that is greater than zero, the animation begins after that amount of time has elapsed from the time the next frame is rendered.
作成 HandoffBehavior の使用Using the Compose HandoffBehavior
を使用してStoryboard AnimationTimeline AnimationClock プロパティにClock 、、またはを適用すると、そのプロパティに以前関連付けられていたすべてのオブジェクトが引き続きシステムリソースを消費します。タイミングシステムは、HandoffBehavior Composeこれらのクロックは自動的に削除されます。When you apply a Storyboard, AnimationTimeline, or AnimationClock to a property using the Compose HandoffBehavior, any Clock objects previously associated with that property continue to consume system resources; the timing system will not remove these clocks automatically.
を使用してCompose多数のクロックを適用するときのパフォーマンスの問題を回避するには、アニメーション化されたプロパティの完了後に、構成クロックを削除する必要があります。To avoid performance issues when you apply a large number of clocks using Compose, you should remove composing clocks from the animated property after they complete. クロックを削除する方法はいくつかあります。There are several ways to remove a clock.
プロパティからすべてのクロックを削除するにApplyAnimationClock(DependencyProperty, AnimationClock)は、アニメーション化されたオブジェクトのメソッドまたはBeginAnimation(DependencyProperty, AnimationTimeline)メソッドを使用します。To remove all clocks from a property, use the ApplyAnimationClock(DependencyProperty, AnimationClock) or BeginAnimation(DependencyProperty, AnimationTimeline) method of the animated object. アニメーション化するプロパティを最初のパラメーターとして
null
指定し、2番目のパラメーターとして指定します。Specify the property being animated as the first parameter, andnull
as the second. これにより、すべてのアニメーション クロックがプロパティから削除されます。This will remove all animation clocks from the property.クロックのリストからAnimationClock特定のを削除するには、 ControllerのプロパティAnimationClockを使用してClockController ClockControllerを取得し、 Removeのメソッドを呼び出します。To remove a specific AnimationClock from a list of clocks, use the Controller property of the AnimationClock to retrieve a ClockController, then call the Remove method of the ClockController. これは通常、クロックのCompletedイベントハンドラーで実行されます。This is typically done in the Completed event handler for a clock. によってClockController Controller制御できるのはルートクロックのみであることに注意してください。
null
子クロックのプロパティはを返します。Note that only root clocks can be controlled by a ClockController; the Controller property of a child clock will returnnull
. また、クロックのCompleted有効期間が無期限の場合は、イベントが呼び出されないことにも注意してください。Note also that the Completed event will not be called if the effective duration of the clock is forever. その場合は、を呼び出すRemoveタイミングをユーザーが決定する必要があります。In that case, the user will need to determine when to call Remove.
これは主に、有効期間が長いオブジェクトでのアニメーションの問題です。This is primarily an issue for animations on objects that have a long lifetime. オブジェクトがガベージ コレクションされる場合は、そのクロックも切断されて、ガベージ コレクションされます。When an object is garbage collected, its clocks will also be disconnected and garbage collected.
クロックオブジェクトの詳細については、「アニメーションとタイミングシステムの概要」を参照してください。For more information about clock objects, see the Animation and Timing System Overview.