private void Restore(ListBox menu) { menu.IsEnabled = false; menu.Visibility = Visibility.Visible; var breadcrumbItem = BreadcrumbContainer.Items.Count > 0 ? (ListBoxItem)BreadcrumbContainer.Items[BreadcrumbContainer.Items.Count - 1] : null; Point origin = new Point(0, 0), menuPoint = menu.TranslatePoint(origin, this), breadcrumbPoint = breadcrumbItem == null ? origin : breadcrumbItem.TranslatePoint(origin, this) ; var duration = new Duration(TimeSpan.FromMilliseconds(300)); DoubleAnimation posXAnimation = new DoubleAnimation { Duration = duration, From = breadcrumbPoint.X - menuPoint.X }, posYAnimation = new DoubleAnimation { Duration = duration, From = breadcrumbPoint.Y - menuPoint.Y }, scaleXAnimation = new DoubleAnimation { Duration = duration, From = 0.3 }, scaleYAnimation = new DoubleAnimation { Duration = duration, From = 0.3 }, opacityAnimation = new DoubleAnimation { Duration = duration, From = 0 } ; var translateTransform = ((TransformGroup)menu.RenderTransform).Children[0]; var scaleTransform = ((TransformGroup)menu.RenderTransform).Children[1]; translateTransform.BeginAnimation(TranslateTransform.XProperty, posXAnimation); translateTransform.BeginAnimation(TranslateTransform.YProperty, posYAnimation); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, scaleXAnimation); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, scaleYAnimation); opacityAnimation.Completed += (object sender, EventArgs e) => { menu.IsEnabled = true; translateTransform.BeginAnimation(TranslateTransform.XProperty, null); translateTransform.BeginAnimation(TranslateTransform.YProperty, null); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, null); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, null); menu.BeginAnimation(OpacityProperty, null); }; menu.BeginAnimation(OpacityProperty, opacityAnimation); }
private void Discard(ListBox menu) { menu.IsEnabled = false; var duration = new Duration(TimeSpan.FromMilliseconds(400)); DoubleAnimation posXAnimation = new DoubleAnimation { Duration = duration, To = -80 }, posYAnimation = new DoubleAnimation { Duration = duration, To = -80 }, scaleXAnimation = new DoubleAnimation { Duration = duration, To = 1.5 }, scaleYAnimation = new DoubleAnimation { Duration = duration, To = 1.5 }, opacityAnimation = new DoubleAnimation { Duration = duration, To = 0 } ; var translateTransform = ((TransformGroup)menu.RenderTransform).Children[0]; var scaleTransform = ((TransformGroup)menu.RenderTransform).Children[1]; translateTransform.BeginAnimation(TranslateTransform.XProperty, posXAnimation); translateTransform.BeginAnimation(TranslateTransform.YProperty, posYAnimation); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, scaleXAnimation); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, scaleYAnimation); opacityAnimation.Completed += (object sender, EventArgs e) => { menu.Visibility = Visibility.Collapsed; menu.IsEnabled = true; translateTransform.BeginAnimation(TranslateTransform.XProperty, null); translateTransform.BeginAnimation(TranslateTransform.YProperty, null); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, null); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, null); menu.BeginAnimation(OpacityProperty, null); }; menu.BeginAnimation(OpacityProperty, opacityAnimation); }
static public void MenuAnimation(DoubleAnimation animation, ListBox lb, DependencyProperty dp, int size) { animation.To = size; lb.BeginAnimation(dp, animation, HandoffBehavior.Compose); }