Exemplo n.º 1
0
        private void OpenOrClose()
        {
            if (!_isBound)
            {
                return;
            }

            if (IsOpen)
            {
                if (!StaysOpen)
                {
                    Mouse.AddPreviewMouseDownOutsideCapturedElementHandler(this, OnLostMouseCapture);
                    Mouse.Capture(this, CaptureMode.SubTree);
                }
            }
            switch (Placement)
            {
            case DrawerPlacement.Left:
            case DrawerPlacement.Right:
                if (double.IsPositiveInfinity(MaxWidth))
                {
                    return;
                }
                AnimationUtil.BeginDoubleAnimation(this, WidthProperty, double.IsNaN(Width) ? 0 : Width, IsOpen ? (MaxWidth - ShadowHelper.GetBlurRadius(this)) : MinWidth, IsLoaded ? AnimationDuration : TimeSpan.Zero, null, AnimationEase);
                break;

            default:
                if (double.IsPositiveInfinity(MaxHeight))
                {
                    throw new Exception("Drawer.MaxHeight must have a ensured value.");
                }
                AnimationUtil.BeginDoubleAnimation(this, HeightProperty, double.IsNaN(Height) ? 0 : Height, IsOpen ? (MaxHeight - ShadowHelper.GetBlurRadius(this)) : MinHeight, IsLoaded ? AnimationDuration : TimeSpan.Zero, null, AnimationEase);;
                break;
            }
        }
        private static void Element_Selected(object sender, RoutedEventArgs e)
        {
            var element = (FrameworkElement)sender;

            if (element.GetValue(SelectedShadowColorProperty) is Color selectedShadowColor)
            {
                var effect = GetEffect(element);
                if (effect == null)
                {
                    effect = new DropShadowEffect()
                    {
                        Color         = selectedShadowColor,
                        ShadowDepth   = ShadowHelper.GetShadowDepth(element),
                        Direction     = ShadowHelper.GetDirection(element),
                        BlurRadius    = ShadowHelper.GetBlurRadius(element),
                        Opacity       = 0,
                        RenderingBias = ShadowHelper.GetRenderingBias(element),
                    };
                    AnimationUtil.BeginDoubleAnimation(effect, DropShadowEffect.OpacityProperty, null, ShadowHelper.GetOpacity(element), GlobalSettings.Setting.AnimationDuration);
                    SetEffect(element, effect);
                }
                else
                {
                    AnimationUtil.BeginDoubleAnimation(effect, DropShadowEffect.OpacityProperty, null, ShadowHelper.GetOpacity(element), GlobalSettings.Setting.AnimationDuration);
                    AnimationUtil.BeginColorAnimation(effect, DropShadowEffect.ColorProperty, null, selectedShadowColor, GlobalSettings.Setting.AnimationDuration);
                }
            }
        }
        private static void Element_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            var element = (FrameworkElement)sender;

            var properties = new List <DependencyProperty>();

            if (!GetHoverBackgroundLock((DependencyObject)sender) && element.GetValue(HoverBackgroundProperty) != null)
            {
                properties.Add(BackgroundProperty);
            }
            if (!GetHoverForegroundLock((DependencyObject)sender) && element.GetValue(HoverForegroundProperty) != null)
            {
                if (element is TextBox || element is PasswordBox)
                {
                    properties.Add(Control.ForegroundProperty);
                }
                else
                {
                    properties.Add(ForegroundProperty);
                }
            }
            if (!GetHoverBorderBrushLock((DependencyObject)sender) && element.GetValue(HoverBorderBrushProperty) != null)
            {
                properties.Add(BorderBrushProperty);
            }
            if (element.GetValue(HoverGlyphBrushProperty) != null)
            {
                properties.Add(GlyphBrushProperty);
            }
            if (element.GetValue(HoverToggleBrushProperty) != null)
            {
                properties.Add(ToggleBrushProperty);
            }
            if (element.GetValue(HoverRibbonLineBrushProperty) != null)
            {
                properties.Add(RibbonLineBrushProperty);
            }
            if (properties.Any())
            {
                AnimationUtil.BeginBrushAnimationStoryboard(element, properties);
            }
            if (element.GetValue(HoverShadowColorProperty) is Color)
            {
                var effect = GetEffect(element);
                if (effect == null)
                {
                    return;
                }
                var shadowColor = element.GetValue(ShadowColorProperty);
                if (shadowColor == null)
                {
                    AnimationUtil.BeginDoubleAnimation(effect, DropShadowEffect.OpacityProperty, null, 0, GlobalSettings.Setting.AnimationDuration);
                }
                else
                {
                    AnimationUtil.BeginColorAnimation(effect, DropShadowEffect.ColorProperty, null, (Color)shadowColor, GlobalSettings.Setting.AnimationDuration);
                }
            }
        }
Exemplo n.º 4
0
 private void OnRotateAngleChanged()
 {
     if (_rotateTransform == null || _rotateTransform.Angle == RotateAngle)
     {
         return;
     }
     AnimationUtil.BeginDoubleAnimation(_rotateTransform, RotateTransform.AngleProperty, null, RotateAngle, AnimationDuration, null, AnimationEase);
 }
Exemplo n.º 5
0
 private void OnScaleYChanged()
 {
     if (_scaleTransform == null || _scaleTransform.ScaleY == ScaleY)
     {
         return;
     }
     AnimationUtil.BeginDoubleAnimation(_scaleTransform, ScaleTransform.ScaleYProperty, null, ScaleY, AnimationDuration, null, AnimationEase);
 }
Exemplo n.º 6
0
 protected override void OnValueChanged(double oldValue, double newValue)
 {
     if (IsLoaded)
     {
         AnimationUtil.BeginDoubleAnimation(this, InternalValueProperty, null, newValue, AnimationDuration, null, AnimationEase);
     }
     else
     {
         InternalValue = newValue;
     }
 }
        private static void Element_GotFocus(object sender, RoutedEventArgs e)
        {
            var element = (FrameworkElement)sender;

            var propertyBrushes = new Dictionary <DependencyProperty, Brush>();

            if (element.GetValue(FocusedBackgroundProperty) is Brush focusedBackground)
            {
                propertyBrushes.Add(BackgroundProperty, focusedBackground);
            }
            if (element.GetValue(FocusedForegroundProperty) is Brush focusedForeground)
            {
                if (element is TextBox || element is PasswordBox)
                {
                    propertyBrushes.Add(Control.ForegroundProperty, focusedForeground);
                }
                propertyBrushes.Add(ForegroundProperty, focusedForeground);
            }
            if (element.GetValue(FocusedBorderBrushProperty) is Brush focusedBorderBrush)
            {
                propertyBrushes.Add(BorderBrushProperty, focusedBorderBrush);
            }
            if (element.GetValue(FocusedWatermarkBrushProperty) is Brush watermarkBrush)
            {
                propertyBrushes.Add(WatermarkBrushProperty, watermarkBrush);
            }
            if (propertyBrushes.Any())
            {
                AnimationUtil.BeginBrushAnimationStoryboard(element, propertyBrushes);
            }
            if (element.GetValue(FocusedShadowColorProperty) is Color focusedShadowColor)
            {
                var effect = GetEffect(element);
                if (effect == null)
                {
                    effect = new DropShadowEffect()
                    {
                        Color         = focusedShadowColor,
                        ShadowDepth   = ShadowHelper.GetShadowDepth(element),
                        Direction     = ShadowHelper.GetDirection(element),
                        BlurRadius    = ShadowHelper.GetBlurRadius(element),
                        Opacity       = 0,
                        RenderingBias = ShadowHelper.GetRenderingBias(element),
                    };
                    AnimationUtil.BeginDoubleAnimation(effect, DropShadowEffect.OpacityProperty, null, ShadowHelper.GetOpacity(element), GlobalSettings.Setting.AnimationDuration);
                    SetEffect(element, effect);
                }
                else
                {
                    AnimationUtil.BeginDoubleAnimation(effect, DropShadowEffect.OpacityProperty, null, ShadowHelper.GetOpacity(element), GlobalSettings.Setting.AnimationDuration);
                    AnimationUtil.BeginColorAnimation(effect, DropShadowEffect.ColorProperty, null, focusedShadowColor, GlobalSettings.Setting.AnimationDuration);
                }
            }
        }
        private static void Element_LostFocus(object sender, RoutedEventArgs e)
        {
            var element = (FrameworkElement)sender;

            var properties = new List <DependencyProperty>();

            if (element.GetValue(FocusedBackgroundProperty) != null)
            {
                properties.Add(BackgroundProperty);
            }
            if (element.GetValue(FocusedForegroundProperty) != null)
            {
                if (element is TextBox || element is PasswordBox)
                {
                    properties.Add(Control.ForegroundProperty);
                }
                properties.Add(ForegroundProperty);
            }
            if (element.GetValue(FocusedBorderBrushProperty) != null)
            {
                properties.Add(BorderBrushProperty);
            }
            if (element.GetValue(FocusedWatermarkBrushProperty) != null)
            {
                properties.Add(WatermarkBrushProperty);
            }
            if (properties.Any())
            {
                AnimationUtil.BeginBrushAnimationStoryboard(element, properties);
            }
            if (element.GetValue(FocusedShadowColorProperty) is Color)
            {
                var effect = GetEffect(element);
                if (effect == null)
                {
                    return;
                }
                var shadowColor = element.GetValue(ShadowColorProperty);
                if (shadowColor == null)
                {
                    AnimationUtil.BeginDoubleAnimation(effect, DropShadowEffect.OpacityProperty, null, 0, GlobalSettings.Setting.AnimationDuration);
                }
                else
                {
                    AnimationUtil.BeginColorAnimation(effect, DropShadowEffect.ColorProperty, null, (Color)shadowColor, GlobalSettings.Setting.AnimationDuration);
                }
            }
        }
Exemplo n.º 9
0
        internal void Close()
        {
            Dispatcher.Invoke(new Action(() =>
            {
                if (_closed)
                {
                    return;
                }
                _closed = true;

                AnimationUtil.BeginDoubleAnimation(this, OpacityProperty, null, 0, _animationDuration, callback: () =>
                {
                    Closed?.Invoke(this, new EventArgs());
                });
            }));
        }
Exemplo n.º 10
0
        private static void ProgressBar_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            var progressBar       = (ProgressBar)sender;
            var newValue          = e.NewValue;
            var animationDuration = GetAnimationDuration(progressBar);
            var animationEase     = GetAnimationEase(progressBar);

            if (progressBar.IsLoaded)
            {
                AnimationUtil.BeginDoubleAnimation(progressBar, ValueProperty, null, newValue, animationDuration, null, animationEase);
            }
            else
            {
                SetValue(progressBar, newValue);
            }
        }
Exemplo n.º 11
0
        private static void OnRemoveCommandExecute(object obj)
        {
            var tabItem           = (TabItem)obj;
            var tabControl        = (TabControl)ItemsControl.ItemsControlFromItemContainer(tabItem);
            var animationDuration = GetRemovingAnimationDuration(tabControl);
            var animationEase     = GetRemovingAnimationEase(tabControl);
            var dataItem          = tabControl.ItemContainerGenerator.ItemFromContainer(tabItem);

            var removingArgs = new ItemRemovingEventArgs(ItemRemovingEvent, dataItem);

            tabControl.RaiseEvent(removingArgs);
            if (removingArgs.Cancel)
            {
                return;
            }

            var action = new Action(() =>
            {
                tabControl.Dispatcher.Invoke(new Action(() =>
                {
                    var collectionView = (IEditableCollectionView)tabControl.Items;
                    if (collectionView.CanRemove)
                    {
                        collectionView.Remove(dataItem);
                    }
                    else
                    {
                        tabControl.Items.Remove(dataItem);
                    }

                    var removedArgs = new ItemRemovedEventArgs(ItemRemovedEvent, dataItem);
                    tabControl.RaiseEvent(removedArgs);
                }));
            });

            if (animationDuration != null && ((TimeSpan)animationDuration).TotalMilliseconds > 0)
            {
                var isLeftRight = tabItem.TabStripPlacement == Dock.Left || tabItem.TabStripPlacement == Dock.Right;
                AnimationUtil.BeginDoubleAnimation(tabItem, isLeftRight ? TabItem.HeightProperty : TabItem.WidthProperty, isLeftRight ? tabItem.ActualHeight : tabItem.ActualWidth, 0, animationDuration, null, animationEase, action);
            }
            else
            {
                action?.Invoke();
            }
        }
        protected override void OnVisualChildrenChanged(DependencyObject visualAdded, DependencyObject visualRemoved)
        {
            var isVertical = Orientation == Orientation.Vertical;

            if (visualAdded is UIElement elementAdded)
            {
                if (isVertical)
                {
                    SetMultiplierX(elementAdded, 1);
                    AnimationUtil.BeginDoubleAnimation(elementAdded, MultiplierXProperty, null, 0, AnimationDuration, ease: AnimationEase);
                }
                else
                {
                    SetMultiplierY(elementAdded, -1);
                    AnimationUtil.BeginDoubleAnimation(elementAdded, MultiplierYProperty, null, 0, AnimationDuration, ease: AnimationEase);
                }
            }
            if (visualRemoved is UIElement elementRemoved)
            {
                var flag = false;
                foreach (UIElement child in InternalChildren)
                {
                    if (flag)
                    {
                        if (isVertical)
                        {
                            SetMultiplierY(child, 1);
                            child.BeginAnimation(MultiplierYProperty, null);
                            AnimationUtil.BeginDoubleAnimation(child, MultiplierYProperty, null, 0, AnimationDuration, ease: AnimationEase);
                        }
                        else
                        {
                            SetMultiplierX(child, 1);
                            child.BeginAnimation(MultiplierXProperty, null);
                            AnimationUtil.BeginDoubleAnimation(child, MultiplierXProperty, null, 0, AnimationDuration, ease: AnimationEase);
                        }
                    }
                    if (child == null)
                    {
                        flag = true;
                    }
                }
            }
            base.OnVisualChildrenChanged(visualAdded, visualRemoved);
        }
Exemplo n.º 13
0
        private static void OnRemoveCommandExecute(object obj)
        {
            var listBoxItem       = (ListBoxItem)obj;
            var listBox           = (ListBox)ItemsControl.ItemsControlFromItemContainer(listBoxItem);
            var animationDuration = GetRemovingAnimationDuration(listBox);
            var animationEase     = GetRemovingAnimationEase(listBox);
            var dataItem          = listBox.ItemContainerGenerator.ItemFromContainer(listBoxItem);

            var removingArgs = new ItemRemovingEventArgs(ItemRemovingEvent, dataItem);

            listBox.RaiseEvent(removingArgs);
            if (removingArgs.Cancel)
            {
                return;
            }

            var action = new Action(() =>
            {
                listBox.Dispatcher.Invoke(new Action(() =>
                {
                    var collectionView = (IEditableCollectionView)listBox.Items;
                    if (collectionView.CanRemove)
                    {
                        collectionView.Remove(dataItem);
                    }
                    else
                    {
                        listBox.Items.Remove(dataItem);
                    }

                    var removedArgs = new ItemRemovedEventArgs(ItemRemovedEvent, dataItem);
                    listBox.RaiseEvent(removedArgs);
                }));
            });

            if (animationDuration != null && ((TimeSpan)animationDuration).TotalMilliseconds > 0)
            {
                AnimationUtil.BeginDoubleAnimation(listBoxItem, ListBoxItem.HeightProperty, null, 0, animationDuration, null, animationEase, action);
            }
            else
            {
                action?.Invoke();
            }
        }
Exemplo n.º 14
0
        private static void Element_Unselected(object sender, RoutedEventArgs e)
        {
            var element = (FrameworkElement)sender;

            if (element.GetValue(SelectedShadowColorProperty) is Color)
            {
                var effect = GetEffect(element);
                if (effect == null)
                {
                    return;
                }
                var shadowColor = element.GetValue(ShadowColorProperty);
                if (shadowColor == null)
                {
                    AnimationUtil.BeginDoubleAnimation(effect, DropShadowEffect.OpacityProperty, null, 0, GlobalSettings.Setting.AnimationDuration);
                }
                else
                {
                    AnimationUtil.BeginColorAnimation(effect, DropShadowEffect.ColorProperty, null, (Color)shadowColor, GlobalSettings.Setting.AnimationDuration);
                }
            }
        }
Exemplo n.º 15
0
        private static void Element_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            var element = (FrameworkElement)sender;

            var propertyBrushes = new Dictionary <DependencyProperty, Brush>();

            if (!GetHoverBackgroundLock((DependencyObject)sender) && element.GetValue(HoverBackgroundProperty) is Brush hoverBackground)
            {
                propertyBrushes.Add(BackgroundProperty, hoverBackground);
            }
            if (!GetHoverForegroundLock((DependencyObject)sender) && element.GetValue(HoverForegroundProperty) is Brush hoverForeground)
            {
                if (element is TextBox || element is PasswordBox)
                {
                    propertyBrushes.Add(Control.ForegroundProperty, hoverForeground);
                }
                else
                {
                    propertyBrushes.Add(ForegroundProperty, hoverForeground);
                }
            }
            if (!GetHoverBorderBrushLock((DependencyObject)sender) && element.GetValue(HoverBorderBrushProperty) is Brush hoverBorderBrush)
            {
                propertyBrushes.Add(BorderBrushProperty, hoverBorderBrush);
            }
            if (element.GetValue(HoverGlyphBrushProperty) is Brush hoverGlyphBrush)
            {
                propertyBrushes.Add(GlyphBrushProperty, hoverGlyphBrush);
            }
            if (element.GetValue(HoverToggleBrushProperty) is Brush hoverToggleBrush)
            {
                propertyBrushes.Add(ToggleBrushProperty, hoverToggleBrush);
            }
            if (element.GetValue(HoverRibbonLineBrushProperty) is Brush hoverRibbonLineBrush)
            {
                propertyBrushes.Add(RibbonLineBrushProperty, hoverRibbonLineBrush);
            }
            if (propertyBrushes.Any())
            {
                AnimationUtil.BeginBrushAnimationStoryboard(element, propertyBrushes);
            }
            if (element.GetValue(HoverShadowColorProperty) is Color hoverShadowColor)
            {
                var effect = GetEffect(element);
                if (effect == null)
                {
                    effect = new DropShadowEffect()
                    {
                        Color         = hoverShadowColor,
                        ShadowDepth   = ShadowHelper.GetShadowDepth(element),
                        Direction     = ShadowHelper.GetDirection(element),
                        BlurRadius    = ShadowHelper.GetBlurRadius(element),
                        Opacity       = 0,
                        RenderingBias = ShadowHelper.GetRenderingBias(element),
                    };
                    AnimationUtil.BeginDoubleAnimation(effect, DropShadowEffect.OpacityProperty, null, ShadowHelper.GetOpacity(element), GlobalSettings.Setting.AnimationDuration);
                    SetEffect(element, effect);
                }
                else
                {
                    AnimationUtil.BeginDoubleAnimation(effect, DropShadowEffect.OpacityProperty, null, ShadowHelper.GetOpacity(element), GlobalSettings.Setting.AnimationDuration);
                    AnimationUtil.BeginColorAnimation(effect, DropShadowEffect.ColorProperty, null, hoverShadowColor, GlobalSettings.Setting.AnimationDuration);
                }
            }
        }
Exemplo n.º 16
0
        private static void Element_Checked(object sender, RoutedEventArgs e)
        {
            var element = (FrameworkElement)sender;

            AnimationUtil.BeginDoubleAnimation(element, PercentProperty, null, 1, TimeSpan.FromMilliseconds(GlobalSettings.Setting.AnimationDuration.TotalMilliseconds), null, AnimationEase.CubicInOut);
        }