Button background not animated on MouseEnter event












0















I want to animate button's background color with DinamicResources. To do this i create attached DependencyProperty:



namespace ModPlusStyle.Controls.Helpers
{
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;

public class ButtonAssist
{
private static readonly Dictionary<Button, Color> _initBackgroundBrush = new Dictionary<Button, Color>();

private static readonly Dictionary<Button, Color> _initForegroundBrush = new Dictionary<Button, Color>();

public static readonly DependencyProperty AnimateMouseOverProperty = DependencyProperty.RegisterAttached(
"AnimateMouseOver",
typeof(bool),
typeof(ButtonAssist),
new FrameworkPropertyMetadata(default(bool), FrameworkPropertyMetadataOptions.AffectsRender, AnimateMouseOverChangedCallback));

public static void SetAnimateMouseOver(DependencyObject element, bool value)
{
element.SetValue(AnimateMouseOverProperty, value);
}

public static bool GetAnimateMouseOver(DependencyObject element)
{
return (bool)element.GetValue(AnimateMouseOverProperty);
}

private static void AnimateMouseOverChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is Button button)
{
if ((bool)e.NewValue)
{
button.MouseEnter += ButtonOnMouseEnter;
button.MouseLeave += ButtonOnMouseLeave;
}
else
{
button.MouseEnter -= ButtonOnMouseEnter;
button.MouseLeave -= ButtonOnMouseLeave;
}
}
}

private static void ButtonOnMouseEnter(object sender, MouseEventArgs e)
{
if (sender is Button button &&
!(button.Parent is WindowCommands) &&
button.Background is SolidColorBrush backgroundSolidColorBrush &&
button.Foreground is SolidColorBrush foregroundSolidColorBrush)
{
var parentWindow = Window.GetWindow(button);
if (parentWindow != null)
{
if (parentWindow.Resources["WhiteBrush"] is SolidColorBrush whiteBrush &&
parentWindow.Resources["BlackBrush"] is SolidColorBrush blackBrush)
{
if (_initBackgroundBrush.ContainsKey(button))
_initBackgroundBrush[button] = backgroundSolidColorBrush.Color;
else
_initBackgroundBrush.Add(button, backgroundSolidColorBrush.Color);

if (_initForegroundBrush.ContainsKey(button))
_initForegroundBrush[button] = foregroundSolidColorBrush.Color;
else
_initForegroundBrush.Add(button, foregroundSolidColorBrush.Color);

button.Background = new SolidColorBrush(backgroundSolidColorBrush.Color);
ColorAnimation backgroundColorAnimation = new ColorAnimation(
backgroundSolidColorBrush.Color,
whiteBrush.Color,
new Duration(TimeSpan.FromMilliseconds(300)));
button.Background.BeginAnimation(SolidColorBrush.ColorProperty, backgroundColorAnimation);

button.Foreground = new SolidColorBrush(foregroundSolidColorBrush.Color);
ColorAnimation foregroundColorAnimation = new ColorAnimation(
foregroundSolidColorBrush.Color,
blackBrush.Color,
new Duration(TimeSpan.FromMilliseconds(300)));
button.Foreground.BeginAnimation(SolidColorBrush.ColorProperty, foregroundColorAnimation);
}
}
}
}

private static void ButtonOnMouseLeave(object sender, MouseEventArgs e)
{
if (sender is Button button &&
!(button.Parent is WindowCommands) &&
_initBackgroundBrush.ContainsKey(button) &&
_initForegroundBrush.ContainsKey(button))
{
var parentWindow = Window.GetWindow(button);
if (parentWindow != null)
{
if (parentWindow.Resources["AccentColorBrush"] is SolidColorBrush accentColorBrush &&
parentWindow.Resources["ForegroundForAccentedBrush"] is SolidColorBrush foregroundForAccentedBrush)
{
button.Background = new SolidColorBrush(((SolidColorBrush)button.Background).Color);
ColorAnimation backgroundColorAnimation = new ColorAnimation(
((SolidColorBrush)button.Background).Color,
_initBackgroundBrush[button],
new Duration(TimeSpan.FromMilliseconds(300)));
backgroundColorAnimation.Completed += (o, args) =>
{
if (_initBackgroundBrush[button] == accentColorBrush.Color)
button.SetResourceReference(Control.BackgroundProperty, "AccentColorBrush");
_initBackgroundBrush.Remove(button);
};
button.Background.BeginAnimation(SolidColorBrush.ColorProperty, backgroundColorAnimation);

button.Foreground = new SolidColorBrush(((SolidColorBrush)button.Foreground).Color);
ColorAnimation foregroundColorAnimation = new ColorAnimation(
((SolidColorBrush)button.Foreground).Color,
_initForegroundBrush[button],
new Duration(TimeSpan.FromMilliseconds(300)));
foregroundColorAnimation.Completed += (o, args) =>
{
if (_initForegroundBrush[button] == foregroundForAccentedBrush.Color)
button.SetResourceReference(Control.ForegroundProperty, "ForegroundForAccentedBrush");
_initForegroundBrush.Remove(button);
};
button.Foreground.BeginAnimation(SolidColorBrush.ColorProperty, foregroundColorAnimation);
}
}
}
}
}
}


I set value in button's style:



<Style x:Key="ModPlusAccentButton" TargetType="{x:Type ButtonBase}">
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
<Setter Property="Background" Value="{DynamicResource AccentColorBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource AccentColorBrush}" />
<Setter Property="Foreground" Value="{DynamicResource ForegroundForAccentedBrush}" />
<Setter Property="Padding" Value="12 6 12 6" />
<Setter Property="helpers:ButtonAssist.AnimateMouseOver" Value="True"></Setter>
<Setter Property="SnapsToDevicePixels" Value="True" />
.......


In debug i get the right colors in ButtonOnMouseEnter method. But button's background not changed
jig example



However, the animation in the ButtonOnMouseLeave method works correctly!



Why so?










share|improve this question



























    0















    I want to animate button's background color with DinamicResources. To do this i create attached DependencyProperty:



    namespace ModPlusStyle.Controls.Helpers
    {
    using System;
    using System.Collections.Generic;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;

    public class ButtonAssist
    {
    private static readonly Dictionary<Button, Color> _initBackgroundBrush = new Dictionary<Button, Color>();

    private static readonly Dictionary<Button, Color> _initForegroundBrush = new Dictionary<Button, Color>();

    public static readonly DependencyProperty AnimateMouseOverProperty = DependencyProperty.RegisterAttached(
    "AnimateMouseOver",
    typeof(bool),
    typeof(ButtonAssist),
    new FrameworkPropertyMetadata(default(bool), FrameworkPropertyMetadataOptions.AffectsRender, AnimateMouseOverChangedCallback));

    public static void SetAnimateMouseOver(DependencyObject element, bool value)
    {
    element.SetValue(AnimateMouseOverProperty, value);
    }

    public static bool GetAnimateMouseOver(DependencyObject element)
    {
    return (bool)element.GetValue(AnimateMouseOverProperty);
    }

    private static void AnimateMouseOverChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
    if (d is Button button)
    {
    if ((bool)e.NewValue)
    {
    button.MouseEnter += ButtonOnMouseEnter;
    button.MouseLeave += ButtonOnMouseLeave;
    }
    else
    {
    button.MouseEnter -= ButtonOnMouseEnter;
    button.MouseLeave -= ButtonOnMouseLeave;
    }
    }
    }

    private static void ButtonOnMouseEnter(object sender, MouseEventArgs e)
    {
    if (sender is Button button &&
    !(button.Parent is WindowCommands) &&
    button.Background is SolidColorBrush backgroundSolidColorBrush &&
    button.Foreground is SolidColorBrush foregroundSolidColorBrush)
    {
    var parentWindow = Window.GetWindow(button);
    if (parentWindow != null)
    {
    if (parentWindow.Resources["WhiteBrush"] is SolidColorBrush whiteBrush &&
    parentWindow.Resources["BlackBrush"] is SolidColorBrush blackBrush)
    {
    if (_initBackgroundBrush.ContainsKey(button))
    _initBackgroundBrush[button] = backgroundSolidColorBrush.Color;
    else
    _initBackgroundBrush.Add(button, backgroundSolidColorBrush.Color);

    if (_initForegroundBrush.ContainsKey(button))
    _initForegroundBrush[button] = foregroundSolidColorBrush.Color;
    else
    _initForegroundBrush.Add(button, foregroundSolidColorBrush.Color);

    button.Background = new SolidColorBrush(backgroundSolidColorBrush.Color);
    ColorAnimation backgroundColorAnimation = new ColorAnimation(
    backgroundSolidColorBrush.Color,
    whiteBrush.Color,
    new Duration(TimeSpan.FromMilliseconds(300)));
    button.Background.BeginAnimation(SolidColorBrush.ColorProperty, backgroundColorAnimation);

    button.Foreground = new SolidColorBrush(foregroundSolidColorBrush.Color);
    ColorAnimation foregroundColorAnimation = new ColorAnimation(
    foregroundSolidColorBrush.Color,
    blackBrush.Color,
    new Duration(TimeSpan.FromMilliseconds(300)));
    button.Foreground.BeginAnimation(SolidColorBrush.ColorProperty, foregroundColorAnimation);
    }
    }
    }
    }

    private static void ButtonOnMouseLeave(object sender, MouseEventArgs e)
    {
    if (sender is Button button &&
    !(button.Parent is WindowCommands) &&
    _initBackgroundBrush.ContainsKey(button) &&
    _initForegroundBrush.ContainsKey(button))
    {
    var parentWindow = Window.GetWindow(button);
    if (parentWindow != null)
    {
    if (parentWindow.Resources["AccentColorBrush"] is SolidColorBrush accentColorBrush &&
    parentWindow.Resources["ForegroundForAccentedBrush"] is SolidColorBrush foregroundForAccentedBrush)
    {
    button.Background = new SolidColorBrush(((SolidColorBrush)button.Background).Color);
    ColorAnimation backgroundColorAnimation = new ColorAnimation(
    ((SolidColorBrush)button.Background).Color,
    _initBackgroundBrush[button],
    new Duration(TimeSpan.FromMilliseconds(300)));
    backgroundColorAnimation.Completed += (o, args) =>
    {
    if (_initBackgroundBrush[button] == accentColorBrush.Color)
    button.SetResourceReference(Control.BackgroundProperty, "AccentColorBrush");
    _initBackgroundBrush.Remove(button);
    };
    button.Background.BeginAnimation(SolidColorBrush.ColorProperty, backgroundColorAnimation);

    button.Foreground = new SolidColorBrush(((SolidColorBrush)button.Foreground).Color);
    ColorAnimation foregroundColorAnimation = new ColorAnimation(
    ((SolidColorBrush)button.Foreground).Color,
    _initForegroundBrush[button],
    new Duration(TimeSpan.FromMilliseconds(300)));
    foregroundColorAnimation.Completed += (o, args) =>
    {
    if (_initForegroundBrush[button] == foregroundForAccentedBrush.Color)
    button.SetResourceReference(Control.ForegroundProperty, "ForegroundForAccentedBrush");
    _initForegroundBrush.Remove(button);
    };
    button.Foreground.BeginAnimation(SolidColorBrush.ColorProperty, foregroundColorAnimation);
    }
    }
    }
    }
    }
    }


    I set value in button's style:



    <Style x:Key="ModPlusAccentButton" TargetType="{x:Type ButtonBase}">
    <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
    <Setter Property="Background" Value="{DynamicResource AccentColorBrush}" />
    <Setter Property="BorderBrush" Value="{DynamicResource AccentColorBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource ForegroundForAccentedBrush}" />
    <Setter Property="Padding" Value="12 6 12 6" />
    <Setter Property="helpers:ButtonAssist.AnimateMouseOver" Value="True"></Setter>
    <Setter Property="SnapsToDevicePixels" Value="True" />
    .......


    In debug i get the right colors in ButtonOnMouseEnter method. But button's background not changed
    jig example



    However, the animation in the ButtonOnMouseLeave method works correctly!



    Why so?










    share|improve this question

























      0












      0








      0








      I want to animate button's background color with DinamicResources. To do this i create attached DependencyProperty:



      namespace ModPlusStyle.Controls.Helpers
      {
      using System;
      using System.Collections.Generic;
      using System.Windows;
      using System.Windows.Controls;
      using System.Windows.Input;
      using System.Windows.Media;
      using System.Windows.Media.Animation;

      public class ButtonAssist
      {
      private static readonly Dictionary<Button, Color> _initBackgroundBrush = new Dictionary<Button, Color>();

      private static readonly Dictionary<Button, Color> _initForegroundBrush = new Dictionary<Button, Color>();

      public static readonly DependencyProperty AnimateMouseOverProperty = DependencyProperty.RegisterAttached(
      "AnimateMouseOver",
      typeof(bool),
      typeof(ButtonAssist),
      new FrameworkPropertyMetadata(default(bool), FrameworkPropertyMetadataOptions.AffectsRender, AnimateMouseOverChangedCallback));

      public static void SetAnimateMouseOver(DependencyObject element, bool value)
      {
      element.SetValue(AnimateMouseOverProperty, value);
      }

      public static bool GetAnimateMouseOver(DependencyObject element)
      {
      return (bool)element.GetValue(AnimateMouseOverProperty);
      }

      private static void AnimateMouseOverChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
      {
      if (d is Button button)
      {
      if ((bool)e.NewValue)
      {
      button.MouseEnter += ButtonOnMouseEnter;
      button.MouseLeave += ButtonOnMouseLeave;
      }
      else
      {
      button.MouseEnter -= ButtonOnMouseEnter;
      button.MouseLeave -= ButtonOnMouseLeave;
      }
      }
      }

      private static void ButtonOnMouseEnter(object sender, MouseEventArgs e)
      {
      if (sender is Button button &&
      !(button.Parent is WindowCommands) &&
      button.Background is SolidColorBrush backgroundSolidColorBrush &&
      button.Foreground is SolidColorBrush foregroundSolidColorBrush)
      {
      var parentWindow = Window.GetWindow(button);
      if (parentWindow != null)
      {
      if (parentWindow.Resources["WhiteBrush"] is SolidColorBrush whiteBrush &&
      parentWindow.Resources["BlackBrush"] is SolidColorBrush blackBrush)
      {
      if (_initBackgroundBrush.ContainsKey(button))
      _initBackgroundBrush[button] = backgroundSolidColorBrush.Color;
      else
      _initBackgroundBrush.Add(button, backgroundSolidColorBrush.Color);

      if (_initForegroundBrush.ContainsKey(button))
      _initForegroundBrush[button] = foregroundSolidColorBrush.Color;
      else
      _initForegroundBrush.Add(button, foregroundSolidColorBrush.Color);

      button.Background = new SolidColorBrush(backgroundSolidColorBrush.Color);
      ColorAnimation backgroundColorAnimation = new ColorAnimation(
      backgroundSolidColorBrush.Color,
      whiteBrush.Color,
      new Duration(TimeSpan.FromMilliseconds(300)));
      button.Background.BeginAnimation(SolidColorBrush.ColorProperty, backgroundColorAnimation);

      button.Foreground = new SolidColorBrush(foregroundSolidColorBrush.Color);
      ColorAnimation foregroundColorAnimation = new ColorAnimation(
      foregroundSolidColorBrush.Color,
      blackBrush.Color,
      new Duration(TimeSpan.FromMilliseconds(300)));
      button.Foreground.BeginAnimation(SolidColorBrush.ColorProperty, foregroundColorAnimation);
      }
      }
      }
      }

      private static void ButtonOnMouseLeave(object sender, MouseEventArgs e)
      {
      if (sender is Button button &&
      !(button.Parent is WindowCommands) &&
      _initBackgroundBrush.ContainsKey(button) &&
      _initForegroundBrush.ContainsKey(button))
      {
      var parentWindow = Window.GetWindow(button);
      if (parentWindow != null)
      {
      if (parentWindow.Resources["AccentColorBrush"] is SolidColorBrush accentColorBrush &&
      parentWindow.Resources["ForegroundForAccentedBrush"] is SolidColorBrush foregroundForAccentedBrush)
      {
      button.Background = new SolidColorBrush(((SolidColorBrush)button.Background).Color);
      ColorAnimation backgroundColorAnimation = new ColorAnimation(
      ((SolidColorBrush)button.Background).Color,
      _initBackgroundBrush[button],
      new Duration(TimeSpan.FromMilliseconds(300)));
      backgroundColorAnimation.Completed += (o, args) =>
      {
      if (_initBackgroundBrush[button] == accentColorBrush.Color)
      button.SetResourceReference(Control.BackgroundProperty, "AccentColorBrush");
      _initBackgroundBrush.Remove(button);
      };
      button.Background.BeginAnimation(SolidColorBrush.ColorProperty, backgroundColorAnimation);

      button.Foreground = new SolidColorBrush(((SolidColorBrush)button.Foreground).Color);
      ColorAnimation foregroundColorAnimation = new ColorAnimation(
      ((SolidColorBrush)button.Foreground).Color,
      _initForegroundBrush[button],
      new Duration(TimeSpan.FromMilliseconds(300)));
      foregroundColorAnimation.Completed += (o, args) =>
      {
      if (_initForegroundBrush[button] == foregroundForAccentedBrush.Color)
      button.SetResourceReference(Control.ForegroundProperty, "ForegroundForAccentedBrush");
      _initForegroundBrush.Remove(button);
      };
      button.Foreground.BeginAnimation(SolidColorBrush.ColorProperty, foregroundColorAnimation);
      }
      }
      }
      }
      }
      }


      I set value in button's style:



      <Style x:Key="ModPlusAccentButton" TargetType="{x:Type ButtonBase}">
      <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
      <Setter Property="Background" Value="{DynamicResource AccentColorBrush}" />
      <Setter Property="BorderBrush" Value="{DynamicResource AccentColorBrush}" />
      <Setter Property="Foreground" Value="{DynamicResource ForegroundForAccentedBrush}" />
      <Setter Property="Padding" Value="12 6 12 6" />
      <Setter Property="helpers:ButtonAssist.AnimateMouseOver" Value="True"></Setter>
      <Setter Property="SnapsToDevicePixels" Value="True" />
      .......


      In debug i get the right colors in ButtonOnMouseEnter method. But button's background not changed
      jig example



      However, the animation in the ButtonOnMouseLeave method works correctly!



      Why so?










      share|improve this question














      I want to animate button's background color with DinamicResources. To do this i create attached DependencyProperty:



      namespace ModPlusStyle.Controls.Helpers
      {
      using System;
      using System.Collections.Generic;
      using System.Windows;
      using System.Windows.Controls;
      using System.Windows.Input;
      using System.Windows.Media;
      using System.Windows.Media.Animation;

      public class ButtonAssist
      {
      private static readonly Dictionary<Button, Color> _initBackgroundBrush = new Dictionary<Button, Color>();

      private static readonly Dictionary<Button, Color> _initForegroundBrush = new Dictionary<Button, Color>();

      public static readonly DependencyProperty AnimateMouseOverProperty = DependencyProperty.RegisterAttached(
      "AnimateMouseOver",
      typeof(bool),
      typeof(ButtonAssist),
      new FrameworkPropertyMetadata(default(bool), FrameworkPropertyMetadataOptions.AffectsRender, AnimateMouseOverChangedCallback));

      public static void SetAnimateMouseOver(DependencyObject element, bool value)
      {
      element.SetValue(AnimateMouseOverProperty, value);
      }

      public static bool GetAnimateMouseOver(DependencyObject element)
      {
      return (bool)element.GetValue(AnimateMouseOverProperty);
      }

      private static void AnimateMouseOverChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
      {
      if (d is Button button)
      {
      if ((bool)e.NewValue)
      {
      button.MouseEnter += ButtonOnMouseEnter;
      button.MouseLeave += ButtonOnMouseLeave;
      }
      else
      {
      button.MouseEnter -= ButtonOnMouseEnter;
      button.MouseLeave -= ButtonOnMouseLeave;
      }
      }
      }

      private static void ButtonOnMouseEnter(object sender, MouseEventArgs e)
      {
      if (sender is Button button &&
      !(button.Parent is WindowCommands) &&
      button.Background is SolidColorBrush backgroundSolidColorBrush &&
      button.Foreground is SolidColorBrush foregroundSolidColorBrush)
      {
      var parentWindow = Window.GetWindow(button);
      if (parentWindow != null)
      {
      if (parentWindow.Resources["WhiteBrush"] is SolidColorBrush whiteBrush &&
      parentWindow.Resources["BlackBrush"] is SolidColorBrush blackBrush)
      {
      if (_initBackgroundBrush.ContainsKey(button))
      _initBackgroundBrush[button] = backgroundSolidColorBrush.Color;
      else
      _initBackgroundBrush.Add(button, backgroundSolidColorBrush.Color);

      if (_initForegroundBrush.ContainsKey(button))
      _initForegroundBrush[button] = foregroundSolidColorBrush.Color;
      else
      _initForegroundBrush.Add(button, foregroundSolidColorBrush.Color);

      button.Background = new SolidColorBrush(backgroundSolidColorBrush.Color);
      ColorAnimation backgroundColorAnimation = new ColorAnimation(
      backgroundSolidColorBrush.Color,
      whiteBrush.Color,
      new Duration(TimeSpan.FromMilliseconds(300)));
      button.Background.BeginAnimation(SolidColorBrush.ColorProperty, backgroundColorAnimation);

      button.Foreground = new SolidColorBrush(foregroundSolidColorBrush.Color);
      ColorAnimation foregroundColorAnimation = new ColorAnimation(
      foregroundSolidColorBrush.Color,
      blackBrush.Color,
      new Duration(TimeSpan.FromMilliseconds(300)));
      button.Foreground.BeginAnimation(SolidColorBrush.ColorProperty, foregroundColorAnimation);
      }
      }
      }
      }

      private static void ButtonOnMouseLeave(object sender, MouseEventArgs e)
      {
      if (sender is Button button &&
      !(button.Parent is WindowCommands) &&
      _initBackgroundBrush.ContainsKey(button) &&
      _initForegroundBrush.ContainsKey(button))
      {
      var parentWindow = Window.GetWindow(button);
      if (parentWindow != null)
      {
      if (parentWindow.Resources["AccentColorBrush"] is SolidColorBrush accentColorBrush &&
      parentWindow.Resources["ForegroundForAccentedBrush"] is SolidColorBrush foregroundForAccentedBrush)
      {
      button.Background = new SolidColorBrush(((SolidColorBrush)button.Background).Color);
      ColorAnimation backgroundColorAnimation = new ColorAnimation(
      ((SolidColorBrush)button.Background).Color,
      _initBackgroundBrush[button],
      new Duration(TimeSpan.FromMilliseconds(300)));
      backgroundColorAnimation.Completed += (o, args) =>
      {
      if (_initBackgroundBrush[button] == accentColorBrush.Color)
      button.SetResourceReference(Control.BackgroundProperty, "AccentColorBrush");
      _initBackgroundBrush.Remove(button);
      };
      button.Background.BeginAnimation(SolidColorBrush.ColorProperty, backgroundColorAnimation);

      button.Foreground = new SolidColorBrush(((SolidColorBrush)button.Foreground).Color);
      ColorAnimation foregroundColorAnimation = new ColorAnimation(
      ((SolidColorBrush)button.Foreground).Color,
      _initForegroundBrush[button],
      new Duration(TimeSpan.FromMilliseconds(300)));
      foregroundColorAnimation.Completed += (o, args) =>
      {
      if (_initForegroundBrush[button] == foregroundForAccentedBrush.Color)
      button.SetResourceReference(Control.ForegroundProperty, "ForegroundForAccentedBrush");
      _initForegroundBrush.Remove(button);
      };
      button.Foreground.BeginAnimation(SolidColorBrush.ColorProperty, foregroundColorAnimation);
      }
      }
      }
      }
      }
      }


      I set value in button's style:



      <Style x:Key="ModPlusAccentButton" TargetType="{x:Type ButtonBase}">
      <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
      <Setter Property="Background" Value="{DynamicResource AccentColorBrush}" />
      <Setter Property="BorderBrush" Value="{DynamicResource AccentColorBrush}" />
      <Setter Property="Foreground" Value="{DynamicResource ForegroundForAccentedBrush}" />
      <Setter Property="Padding" Value="12 6 12 6" />
      <Setter Property="helpers:ButtonAssist.AnimateMouseOver" Value="True"></Setter>
      <Setter Property="SnapsToDevicePixels" Value="True" />
      .......


      In debug i get the right colors in ButtonOnMouseEnter method. But button's background not changed
      jig example



      However, the animation in the ButtonOnMouseLeave method works correctly!



      Why so?







      c# wpf animation colors






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 30 '18 at 17:20









      Александр ПекшевАлександр Пекшев

      345




      345
























          1 Answer
          1






          active

          oldest

          votes


















          0














          The problem wath in ClipBorder that used in button's template. Change to Border and it start works






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53979782%2fbutton-background-not-animated-on-mouseenter-event%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            The problem wath in ClipBorder that used in button's template. Change to Border and it start works






            share|improve this answer




























              0














              The problem wath in ClipBorder that used in button's template. Change to Border and it start works






              share|improve this answer


























                0












                0








                0







                The problem wath in ClipBorder that used in button's template. Change to Border and it start works






                share|improve this answer













                The problem wath in ClipBorder that used in button's template. Change to Border and it start works







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 30 '18 at 17:38









                Александр ПекшевАлександр Пекшев

                345




                345






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53979782%2fbutton-background-not-animated-on-mouseenter-event%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Monofisismo

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas