void BackstageButton_Click(object sender, RoutedEventArgs e)
        {
            ModernWindow window    = Window.GetWindow(e.Source as DependencyObject) as ModernWindow;
            var          template  = window.Template;
            Border       container = template.FindName("BackstageContainer", window) as Border;

            if (container.Visibility == Visibility.Collapsed)
            {
                container.Visibility = Visibility.Visible;
            }
            else
            {
                if (window.BackstagePanel != null)
                {
                    foreach (var item in window.BackstagePanel.Items)
                    {
                        if (item is TabItem tabItem && tabItem.Content is ModernContent mc && !mc.CanBeClosed())
                        {
                            return;
                        }
                    }
                }


                if (HideContentStoryboard == null)
                {
                    HideContentStoryboard            = ((Storyboard)container.FindResource("HideContentStoryboard")).Clone();
                    HideContentStoryboard.Completed += (s, e2) => HideContentStoryboard_Completed(container, e2);
                }
                container.BeginStoryboard(HideContentStoryboard);
            }
        }
예제 #2
0
        public void Acordeon_Animations(object sender)
        {
            Grid       PanelActual = sender as Grid;
            Grid       Padre       = (Grid)PanelActual.Parent;
            Border     Abuelo      = (Border)Padre.Parent;
            StackPanel BisAbuelo   = (StackPanel)Abuelo.Parent;

            var             altoPanel        = 0.00;
            DoubleAnimation DaSlideDownPanel = new DoubleAnimation();

            DaSlideDownPanel.Duration = new Duration(new TimeSpan(0, 0, 0, 0, 200));

            DoubleAnimation DaSlideUpPanel = new DoubleAnimation();

            DaSlideUpPanel.Duration = new Duration(new TimeSpan(0, 0, 0, 0, 200));

            //Primero: Cerrar los paneles abiertos
            foreach (Border item in Accesoria.FindVisualChildren2 <Border>(BisAbuelo, 2))
            {
                if (item.Height > 35)
                {
                    DaSlideUpPanel.To = 35;
                    Storyboard sb1 = new Storyboard();
                    sb1.Children.Add(DaSlideUpPanel);
                    Storyboard.SetTarget(DaSlideUpPanel, item);
                    Storyboard.SetTargetProperty(DaSlideUpPanel, new PropertyPath("Height"));
                    PanelActual.BeginStoryboard(sb1);
                    break;
                }
            }

            //Segundo: Abrir el panel Seleccionado
            if (Abuelo.Height == 35)
            {
                foreach (Grid item in Accesoria.FindVisualChildren2 <Grid>(Abuelo, 1))
                {
                    if (item.Height > 0)
                    {
                        altoPanel = altoPanel + item.Height;
                    }
                }
            }
            else
            {
                altoPanel = 35;
            }
            DaSlideDownPanel.To = altoPanel;
            Storyboard sb = new Storyboard();

            sb.Children.Add(DaSlideDownPanel);
            Storyboard.SetTarget(DaSlideDownPanel, Abuelo);
            Storyboard.SetTargetProperty(DaSlideDownPanel, new PropertyPath("Height"));
            Abuelo.BeginStoryboard(sb);
        }
        void UpdateBorderAndCursor(Rectangle?Rect)
        {
            if (_lastRectangle == Rect)
            {
                return;
            }

            _lastRectangle = Rect;

            var storyboard = new Storyboard();

            var duration = new Duration(TimeSpan.FromMilliseconds(100));

            if (Rect == null)
            {
                Cursor = Cursors.Arrow;

                var opacityAnim = new DoubleAnimation(0, duration);
                Storyboard.SetTargetProperty(opacityAnim, new PropertyPath(nameof(Opacity)));
                storyboard.Children.Add(opacityAnim);
            }
            else
            {
                Cursor = Cursors.Hand;

                var opacityAnim = new DoubleAnimation(1, duration);
                Storyboard.SetTargetProperty(opacityAnim, new PropertyPath(nameof(Opacity)));
                storyboard.Children.Add(opacityAnim);

                var rect = Rect.Value;

                var margin     = new Thickness(-Left + rect.Left / Dpi.X, -Top + rect.Top / Dpi.Y, 0, 0);
                var marginAnim = new ThicknessAnimation(margin, duration);
                Storyboard.SetTargetProperty(marginAnim, new PropertyPath(nameof(Margin)));
                storyboard.Children.Add(marginAnim);

                var widthAnim = new DoubleAnimation(Border.ActualWidth, rect.Width / Dpi.X, duration);
                Storyboard.SetTargetProperty(widthAnim, new PropertyPath(nameof(Width)));
                storyboard.Children.Add(widthAnim);

                var heightAnim = new DoubleAnimation(Border.ActualHeight, rect.Height / Dpi.Y, duration);
                Storyboard.SetTargetProperty(heightAnim, new PropertyPath(nameof(Height)));
                storyboard.Children.Add(heightAnim);
            }

            Border.BeginStoryboard(storyboard);
        }
예제 #4
0
        // 关闭对话框动作
        private void CloseAnimaton()
        {
            // 退出动画
            Storyboard exitStoryboard = new Storyboard();

            DoubleAnimation exitOpacityAnimation = new DoubleAnimation
            {
                From           = 1,
                To             = 0,
                Duration       = new Duration(TimeSpan.FromMilliseconds(200)),
                EasingFunction = new CubicEase {
                    EasingMode = EasingMode.EaseIn
                }
            };

            Storyboard.SetTargetProperty(exitOpacityAnimation, new PropertyPath(FrameworkElement.OpacityProperty));

            DoubleAnimation exitTransformAnimation = new DoubleAnimation
            {
                From           = 0,
                To             = 50,
                Duration       = new Duration(TimeSpan.FromMilliseconds(200)),
                EasingFunction = new CubicEase {
                    EasingMode = EasingMode.EaseIn
                }
            };

            Storyboard.SetTargetProperty(exitTransformAnimation, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.Y)"));

            exitStoryboard.Children.Add(exitOpacityAnimation);
            exitStoryboard.Children.Add(exitTransformAnimation);

            // 背景动画
            ColorAnimation backgroundAnimation = new ColorAnimation
            {
                To             = Colors.Transparent,
                Duration       = new Duration(TimeSpan.FromMilliseconds(150)),
                EasingFunction = new CubicEase {
                    EasingMode = EasingMode.EaseIn
                }
            };

            // 退出动画完成
            exitStoryboard.Completed += (a, b) =>
            {
                rootBorder.Background.BeginAnimation(SolidColorBrush.ColorProperty, backgroundAnimation);
                cardBorder.Visibility = Visibility.Hidden;

                RoutedPropertyChangedEventArgs <object> args = new RoutedPropertyChangedEventArgs <object>(null, this.closeParameter);
                args.RoutedEvent = DialogBox.AfterCloseEvent;
                this.RaiseEvent(args);
                this.AfterCloseCommand?.Execute(this.closeParameter);
                this.afterCloseHandler?.Invoke(this, this.closeParameter);

                this.closeParameter    = null;
                this.beforeOpenHandler = null;
                this.afterCloseHandler = null;
            };

            // 背景动画完成
            backgroundAnimation.Completed += (a, b) =>
            {
                rootBorder.Visibility = Visibility.Hidden;
            };

            cardBorder.BeginStoryboard(exitStoryboard);    // 执行动画
        }