コード例 #1
0
        private static void OnRenderDefaultedChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            MyButtonChrome chrome = (MyButtonChrome)o;

            if (chrome.Animates)
            {
                if (!chrome.RenderPressed)
                {
                    if ((bool)e.NewValue)
                    {
                        if (chrome._localResources == null)
                        {
                            chrome._localResources = new LocalResources();
                            chrome.InvalidateVisual();
                        }
                        Duration               duration      = new Duration(TimeSpan.FromSeconds(0.3));
                        ColorAnimation         animation     = new ColorAnimation(Color.FromArgb(0xf9, 0, 0xcc, 0xff), duration);
                        GradientStopCollection gradientStops = ((LinearGradientBrush)chrome.InnerBorderPen.Brush).GradientStops;
                        gradientStops[0].BeginAnimation(GradientStop.ColorProperty, animation);
                        gradientStops[1].BeginAnimation(GradientStop.ColorProperty, animation);
                        DoubleAnimationUsingKeyFrames timeline = new DoubleAnimationUsingKeyFrames();
                        timeline.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, TimeSpan.FromSeconds(0.5)));
                        timeline.KeyFrames.Add(new DiscreteDoubleKeyFrame(1.0, TimeSpan.FromSeconds(0.75)));
                        timeline.KeyFrames.Add(new LinearDoubleKeyFrame(0.0, TimeSpan.FromSeconds(2.0)));
                        timeline.RepeatBehavior = RepeatBehavior.Forever;
                        Timeline.SetDesiredFrameRate(timeline, 10);
                        chrome.BackgroundOverlay.BeginAnimation(Brush.OpacityProperty, timeline);
                        chrome.BorderOverlayPen.Brush.BeginAnimation(Brush.OpacityProperty, timeline);
                    }
                    else if (chrome._localResources == null)
                    {
                        chrome.InvalidateVisual();
                    }
                    else
                    {
                        Duration        duration2  = new Duration(TimeSpan.FromSeconds(0.2));
                        DoubleAnimation animation2 = new DoubleAnimation
                        {
                            Duration = duration2
                        };
                        chrome.BorderOverlayPen.Brush.BeginAnimation(Brush.OpacityProperty, animation2);
                        chrome.BackgroundOverlay.BeginAnimation(Brush.OpacityProperty, animation2);
                        ColorAnimation animation3 = new ColorAnimation
                        {
                            Duration = duration2
                        };
                        GradientStopCollection stops2 = ((LinearGradientBrush)chrome.InnerBorderPen.Brush).GradientStops;
                        stops2[0].BeginAnimation(GradientStop.ColorProperty, animation3);
                        stops2[1].BeginAnimation(GradientStop.ColorProperty, animation3);
                    }
                }
            }
            else
            {
                chrome._localResources = null;
                chrome.InvalidateVisual();
            }
        }
コード例 #2
0
        private static void OnRenderMouseOverChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            MyButtonChrome chrome = (MyButtonChrome)o;

            if (chrome.Animates)
            {
                if (!chrome.RenderPressed)
                {
                    if ((bool)e.NewValue)
                    {
                        if (chrome._localResources == null)
                        {
                            chrome._localResources = new LocalResources();
                            chrome.InvalidateVisual();
                        }
                        Duration        duration  = new Duration(TimeSpan.FromSeconds(0.3));
                        DoubleAnimation animation = new DoubleAnimation(1.0, duration);
                        chrome.BorderOverlayPen.Brush.BeginAnimation(Brush.OpacityProperty, animation);
                        chrome.BackgroundOverlay.BeginAnimation(Brush.OpacityProperty, animation);
                    }
                    else if (chrome._localResources == null)
                    {
                        chrome.InvalidateVisual();
                    }
                    else if (chrome.RenderDefaulted)
                    {
                        double opacity = chrome.BackgroundOverlay.Opacity;
                        double num2    = (1.0 - opacity) * 0.5;
                        DoubleAnimationUsingKeyFrames timeline = new DoubleAnimationUsingKeyFrames();
                        timeline.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, TimeSpan.FromSeconds(num2)));
                        timeline.KeyFrames.Add(new DiscreteDoubleKeyFrame(1.0, TimeSpan.FromSeconds(num2 + 0.25)));
                        timeline.KeyFrames.Add(new LinearDoubleKeyFrame(0.0, TimeSpan.FromSeconds(num2 + 1.5)));
                        timeline.KeyFrames.Add(new LinearDoubleKeyFrame(opacity, TimeSpan.FromSeconds(2.0)));
                        timeline.RepeatBehavior = RepeatBehavior.Forever;
                        Timeline.SetDesiredFrameRate(timeline, 10);
                        chrome.BackgroundOverlay.BeginAnimation(Brush.OpacityProperty, timeline);
                        chrome.BorderOverlayPen.Brush.BeginAnimation(Brush.OpacityProperty, timeline);
                    }
                    else
                    {
                        Duration        duration2  = new Duration(TimeSpan.FromSeconds(0.2));
                        DoubleAnimation animation2 = new DoubleAnimation
                        {
                            Duration = duration2
                        };
                        chrome.BackgroundOverlay.BeginAnimation(Brush.OpacityProperty, animation2);
                        chrome.BorderOverlayPen.Brush.BeginAnimation(Brush.OpacityProperty, animation2);
                    }
                }
            }
            else
            {
                chrome._localResources = null;
                chrome.InvalidateVisual();
            }
        }
コード例 #3
0
        private static void OnRenderPressedChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            MyButtonChrome chrome = (MyButtonChrome)o;

            if (chrome.Animates)
            {
                if ((bool)e.NewValue)
                {
                    if (chrome._localResources == null)
                    {
                        chrome._localResources = new LocalResources();
                        chrome.InvalidateVisual();
                    }
                    Duration        duration  = new Duration(TimeSpan.FromSeconds(0.1));
                    DoubleAnimation animation = new DoubleAnimation(1.0, duration);
                    chrome.BackgroundOverlay.BeginAnimation(Brush.OpacityProperty, animation);
                    chrome.BorderOverlayPen.Brush.BeginAnimation(Brush.OpacityProperty, animation);
                    chrome.LeftDropShadowBrush.BeginAnimation(Brush.OpacityProperty, animation);
                    chrome.TopDropShadowBrush.BeginAnimation(Brush.OpacityProperty, animation);
                    animation = new DoubleAnimation(0.0, duration);
                    chrome.InnerBorderPen.Brush.BeginAnimation(Brush.OpacityProperty, animation);
                    ColorAnimation         animation2    = new ColorAnimation(Color.FromRgb(0xc2, 0xe4, 0xf6), duration);
                    GradientStopCollection gradientStops = ((LinearGradientBrush)chrome.BackgroundOverlay).GradientStops;
                    gradientStops[0].BeginAnimation(GradientStop.ColorProperty, animation2);
                    gradientStops[1].BeginAnimation(GradientStop.ColorProperty, animation2);
                    animation2 = new ColorAnimation(Color.FromRgb(0xab, 0xda, 0xf3), duration);
                    gradientStops[2].BeginAnimation(GradientStop.ColorProperty, animation2);
                    animation2 = new ColorAnimation(Color.FromRgb(0x90, 0xcb, 0xeb), duration);
                    gradientStops[3].BeginAnimation(GradientStop.ColorProperty, animation2);
                    animation2 = new ColorAnimation(Color.FromRgb(0x2c, 0x62, 0x8b), duration);
                    chrome.BorderOverlayPen.Brush.BeginAnimation(SolidColorBrush.ColorProperty, animation2);
                }
                else if (chrome._localResources == null)
                {
                    chrome.InvalidateVisual();
                }
                else
                {
                    bool            renderMouseOver = chrome.RenderMouseOver;
                    Duration        duration2       = new Duration(TimeSpan.FromSeconds(0.1));
                    DoubleAnimation animation3      = new DoubleAnimation
                    {
                        Duration = duration2
                    };
                    chrome.LeftDropShadowBrush.BeginAnimation(Brush.OpacityProperty, animation3);
                    chrome.TopDropShadowBrush.BeginAnimation(Brush.OpacityProperty, animation3);
                    chrome.InnerBorderPen.Brush.BeginAnimation(Brush.OpacityProperty, animation3);
                    if (!renderMouseOver)
                    {
                        chrome.BorderOverlayPen.Brush.BeginAnimation(Brush.OpacityProperty, animation3);
                        chrome.BackgroundOverlay.BeginAnimation(Brush.OpacityProperty, animation3);
                    }
                    ColorAnimation animation4 = new ColorAnimation
                    {
                        Duration = duration2
                    };
                    chrome.BorderOverlayPen.Brush.BeginAnimation(SolidColorBrush.ColorProperty, animation4);
                    GradientStopCollection stops2 = ((LinearGradientBrush)chrome.BackgroundOverlay).GradientStops;
                    stops2[0].BeginAnimation(GradientStop.ColorProperty, animation4);
                    stops2[1].BeginAnimation(GradientStop.ColorProperty, animation4);
                    stops2[2].BeginAnimation(GradientStop.ColorProperty, animation4);
                    stops2[3].BeginAnimation(GradientStop.ColorProperty, animation4);
                }
            }
            else
            {
                chrome._localResources = null;
                chrome.InvalidateVisual();
            }
        }