private static FloatingBlock CreateBlock(Visual element, AdornerContainer adorner) { Point position = Mouse.GetPosition(adorner.AdornedElement); TranslateTransform translateTransform = new TranslateTransform() { X = position.X + FloatingBlock.GetHorizontalOffset(element), Y = position.Y + FloatingBlock.GetVerticalOffset(element) }; FloatingBlock floatingBlock = new FloatingBlock() { Content = FloatingBlock.GetContent(element), ContentTemplate = FloatingBlock.GetContentTemplate(element) }; TransformGroup transformGroup = new TransformGroup(); transformGroup.Children.Add(translateTransform); floatingBlock.RenderTransform = transformGroup; FloatingBlock floatingBlock1 = floatingBlock; double totalMilliseconds = FloatingBlock.GetDuration(element).TimeSpan.TotalMilliseconds; DoubleAnimation doubleAnimation = AnimationHelper.CreateAnimation(FloatingBlock.GetToX(element) + translateTransform.X, totalMilliseconds); Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.X)", new object[0])); Storyboard.SetTarget(doubleAnimation, floatingBlock1); DoubleAnimation doubleAnimation1 = AnimationHelper.CreateAnimation(FloatingBlock.GetToY(element) + translateTransform.Y, totalMilliseconds); Storyboard.SetTargetProperty(doubleAnimation1, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)", new object[0])); Storyboard.SetTarget(doubleAnimation1, floatingBlock1); DoubleAnimation doubleAnimation2 = AnimationHelper.CreateAnimation(0, totalMilliseconds); Storyboard.SetTargetProperty(doubleAnimation2, new PropertyPath("Opacity", new object[0])); Storyboard.SetTarget(doubleAnimation2, floatingBlock1); Storyboard storyboard = new Storyboard(); storyboard.Completed += new EventHandler((object s, EventArgs e) => { AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(element); if (adornerLayer != null) { adorner.Child = null; adornerLayer.Remove(adorner); } }); storyboard.Children.Add(doubleAnimation); storyboard.Children.Add(doubleAnimation1); storyboard.Children.Add(doubleAnimation2); storyboard.Begin(); return(floatingBlock1); }
private static void Target_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { UIElement uIElement = sender as UIElement; if ((uIElement == null ? false : FloatingBlock.GetReadyToFloat(uIElement))) { AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(uIElement); if (adornerLayer != null) { AdornerContainer adornerContainer = new AdornerContainer(adornerLayer) { IsHitTestVisible = false, }; adornerContainer.Child = FloatingBlock.CreateBlock(uIElement, adornerContainer); adornerLayer.Add(adornerContainer); } FloatingBlock.SetReadyToFloat(uIElement, false); } }
private static void Target_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { FloatingBlock.SetReadyToFloat(sender as DependencyObject, true); }