Style the MouseOver on a Silverlight/WPF button

前端 未结 4 1092
轮回少年
轮回少年 2021-02-19 11:27

Struggling with styling the mouse over for a button ... I have managed to style the button (solid red), but I would like for it to change to solid black whenever a mouse over oc

4条回答
  •  清酒与你
    2021-02-19 12:19

    In WPF:

    Define a storyboard in your resources (any place accessible from the button or its style):

      
        
          
        
      
    

    And in the button, create an event trigger that launches the animation:

    
    

    What you want to animate must explicitly exist. This is why the background is explicitly set a SolidColorBrush, whose color is changed by the storyboard.

    Of course, this should be done through a Style.

    Silverlight only supports the Loaded event on triggers, so you need to attach a real event handler to the button and start the storyboard programatically.

提交回复
热议问题