Created
February 18, 2010 05:41
-
-
Save Vaccano/307383 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void AnimatePaneBox(this IMain form, ContentControl destination, UIElementCollection source, Action<FrameworkElement, IEnumerable<WorkItem>> action, FrameworkElement parent, IEnumerable<WorkItem> itemsToDelselect) | |
{ | |
// Create a NameScope for this page so that | |
// Storyboards can be used. | |
NameScope.SetNameScope((DependencyObject)form, new NameScope()); | |
Canvas containerCanvas = new Canvas(); | |
int curInteration = 0; | |
foreach (FrameworkElement element in source) | |
{ | |
curInteration++; | |
string iterationName = "iter" + curInteration.ToString(); | |
GeneralTransform tranform; | |
try | |
{ | |
// Try to get a transform object. It may not be possible. | |
// (ie if the source or dest is not docked then it will fail and we cannot animate. | |
tranform = element.TransformToVisual(destination); | |
} | |
catch (InvalidOperationException) | |
{ | |
return; | |
} | |
Point rootPoint = tranform.Transform(new Point(0, 0)); | |
Rect sourceRelativeRect = new Rect(rootPoint.X - (destination.ActualWidth / 2), | |
rootPoint.Y - (destination.ActualHeight / 2), element.ActualWidth, element.ActualHeight); | |
RectangleGeometry myRectangleGeometry = new RectangleGeometry { Rect = new Rect(0, 0, 0, 0) }; | |
// Assign the geometry a name so that | |
// it can be targeted by a Storyboard. | |
form.WindowRegisterName(iterationName, myRectangleGeometry); | |
Path myPath = new Path | |
{ | |
Fill = ((Canvas)element).Background, | |
StrokeThickness = 1, | |
Stroke = Brushes.Black, | |
Data = myRectangleGeometry | |
}; | |
RectAnimation myRectAnimation = new RectAnimation | |
{ | |
Duration = TimeSpan.FromSeconds(1), | |
FillBehavior = FillBehavior.Stop, | |
AccelerationRatio = 1, | |
// Set the From and To properties of the animation. | |
From = sourceRelativeRect, | |
To = new Rect(0, 0, 0, 0) | |
}; | |
// Set the animation to target the Rect property | |
// of the object named "MyAnimatedRectangleGeometry." | |
Storyboard.SetTargetName(myRectAnimation, iterationName); | |
Storyboard.SetTargetProperty(myRectAnimation, new PropertyPath(RectangleGeometry.RectProperty)); | |
// Create a storyboard to apply the animation. | |
Storyboard ellipseStoryboard = new Storyboard(); | |
ellipseStoryboard.Children.Add(myRectAnimation); | |
containerCanvas.Children.Add(myPath); | |
// Start the storyboard when the Path loads. | |
myPath.Loaded += ((sender, e) => ellipseStoryboard.Begin((FrameworkElement)form)); | |
object currentContent = destination.Content; | |
ellipseStoryboard.Completed += ((sender, e) => destination.Content = currentContent); | |
ellipseStoryboard.Completed += ((sender, e) => action(parent, itemsToDelselect)); | |
} | |
containerCanvas.Background = Brushes.Transparent; | |
Panel.SetZIndex(containerCanvas, 999); | |
destination.Content = containerCanvas; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment