Current location - Loan Platform Complete Network - Big data management - WPF Let all Button's MouseEnter event and MouseLeave event point to the same function respectively, can it be written as a custom control?
WPF Let all Button's MouseEnter event and MouseLeave event point to the same function respectively, can it be written as a custom control?
You can directly specify the style, it is relatively simple, define the Button's MouseEnter and MouseLeave events in the style, if all the buttons are like this, directly defined as a style can be, if there is a difference, you can specify the style's x:key, and then the buttons that you want to apply this style to point to it can be:

<. ! -- the first, apply to all buttons -- >

<Style TargetType="{x:Type Button}"> the style and trigger you want to define </Style>

<! -- the second one, define an x:key -->

<Style x:key="CustomButton" Target="{x:Type Button}"> the style and trigger you want to define</Style>

Applying the second one on the button, the code looks like this :

<Button Style="{StaticResource CustomButton}">

The above is the practice of defining directly in the xaml, you can also call in the background code, I hope it will help you, if you have any questions, please follow up or Hi