本文整理汇总了C#中ScatterViewItem.BeginStoryboard方法的典型用法代码示例。如果您正苦于以下问题:C# ScatterViewItem.BeginStoryboard方法的具体用法?C# ScatterViewItem.BeginStoryboard怎么用?C# ScatterViewItem.BeginStoryboard使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScatterViewItem
的用法示例。
在下文中一共展示了ScatterViewItem.BeginStoryboard方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: JoinItems
//---------------------------------------------------------//
/// <summary>
/// Animates two ScatterViewItems together and then merges the content of both items into one ScatterViewItem.
/// </summary>
/// <param name="pieceRemaining">The piece that will remain after the join.</param>
/// <param name="pieceBeingRemoved">The piece that will be removed as a result of the join.</param>
private void JoinItems(ScatterViewItem pieceRemaining, ScatterViewItem pieceBeingRemoved)
{
// Simultaneous joins on the same pieces (as in the case where two matching pieces are dropped next
// to each other at the same time) eventually remove both matching pieces. Make sure only one join
// happens at one time.
if (!joinInProgress)
{
joinInProgress = true;
Storyboard join = ((Storyboard)Resources["JoinPiece"]).Clone();
foreach (AnimationTimeline animation in join.Children)
{
// If this is a double animation, then it animates the piece's orientation
DoubleAnimation orientation = animation as DoubleAnimation;
if (orientation != null)
{
orientation.To = pieceRemaining.ActualOrientation;
orientation.From = pieceBeingRemoved.ActualOrientation;
// If two pieces are close in orientation, but seperated by the 0/360 line (i.e. 3 and 357) then don't spin the piece all the way around
if (Math.Abs(pieceRemaining.ActualOrientation - pieceBeingRemoved.ActualOrientation) > 180)
{
orientation.To += orientation.From > orientation.To ? 360 : -360;
}
}
// If this is a point animation, then it animates the piece's center
PointAnimation center = animation as PointAnimation;
if (center != null)
{
center.To = puzzleManager.CalculateJoinAnimationDestination(pieceRemaining, pieceBeingRemoved);
}
// Can't animate values that are set to NaN
if (double.IsNaN(pieceBeingRemoved.Orientation))
{
pieceBeingRemoved.Orientation = pieceBeingRemoved.ActualOrientation;
}
// Set up a callback that passes the ScatterViewItems that will be needed when the animation completes
join.Completed += delegate(object sender, EventArgs e)
{
OnJoinAnimationCompleted(pieceBeingRemoved, pieceRemaining);
};
pieceBeingRemoved.BeginStoryboard(join);
}
}
}
示例2: AddPiece
//---------------------------------------------------------//
/// <summary>
/// Adds a ScatterViewItem to the ScatterView, and animates it
/// on from the specified side of the screen (Left or Right).
/// </summary>
/// <param name="item">The item to add.</param>
/// <param name="fromDirection">The direction from which puzzle pieces enter.</param>
private void AddPiece(ScatterViewItem item, Direction fromDirection)
{
// Add the piece to the ScatterView at the correct location
Debug.Assert(fromDirection == Direction.Right || fromDirection == Direction.Left);
double screenHeight = RootLayout.ActualHeight;
double screenWidth = RootLayout.ActualWidth;
item.Center = fromDirection == Direction.Right ? new Point(screenWidth, screenHeight / 2) : new Point(-100, screenHeight / 2);
item.Orientation = random.Next(0, 360);
scatter.Items.Add(item);
// Load the animation
Storyboard add = ((Storyboard)Resources["AddPiece"]).Clone();
foreach (AnimationTimeline animation in add.Children)
{
// If this is a double animation, it animates the item's orientation
DoubleAnimation orientation = animation as DoubleAnimation;
if (orientation != null)
{
// Spin the orientation a little.
orientation.To = item.Orientation + random.Next(-135, 135);
}
// If this is a point animation, then it animates the item's center
PointAnimation center = animation as PointAnimation;
if (center != null)
{
// Get a random point to animate the item to
center.To = new Point(random.Next(0, (int)(screenHeight + 5)), random.Next(0, (int)screenHeight));
}
}
// Set up a callback that passes the ScatterViewItem that will be needed when the animation completes
add.Completed += delegate(object sender, EventArgs e)
{
OnAddAnimationCompleted(item);
};
// Start the animation
item.BeginStoryboard(add, HandoffBehavior.SnapshotAndReplace);
}