If you set a background image to the button, when the mouse moves over the button, the button becomes a light blue button, the background image disappears, there are many solutions to this problem, I only share my solution.
The first way I used it was to add a picture to the button without setting it in the background.
<button horizontalalignment= "left" margin= "179,56.506,0,0" click= "Button_Click" verticalalignment= "Top" Width= "height=" "borderbrush=" #FF1344EC "grid.row=" 1 "padding=" 2 "> <image source=" Image/dzsp.png " Name= "Btn1image" stretch= "Fill" ></Image> </Button>
The button set in this way does not appear again, but it also exposes another problem, that is, the button does not react when the mouse moves over the button. I hope that the color of the button will change when the mouse is moved to the button. So I used the following method again.
<button width= "margin=" 0,0,0,4 "name=" my "mouseenter=" My_mouseenter "mouseleave=" My_mouseleave "BorderBrush= "{x:null}" > <Button.Template> <controltemplate targettype= "button" &G T <ContentControl> <border borderbrush= "{TemplateBinding BorderBrush}" Borderthickne ss= "{TemplateBinding borderthickness}" > <StackPanel> <stackpanel height= "> <StackPanel.Background> <imagebrush imagesource= "Image/ico_01.png" stretch= "None"/> </StackPanel.Background> </StackPanel> <label borderthickness= "0" padding= "5" fontsize= "+ fontweight=" Semibold "foreground=" WhiTE "horizontalcontentalignment=" Center >XXXX</Label> </stackpanel></borde R> </ContentControl> </ControlTemplate> </Button.Template> </Button>
In this way, the original used to do the background of the picture to separate, originally the picture is an icon plus a paragraph of text, now is the icon is separately made as a picture ico_01.png, and then the original background image of the text placed in the label.
Defines the button's two events MouseEnter and MouseLeave, respectively, for handling mouse move to button and move out button
Private voidMy_mouseenter (Objectsender, MouseEventArgs e) {My. BorderBrush=brushes.red; My. BorderThickness=NewThickness (2.0); My. Opacity=0.5; SS++; } Private voidMy_mouseleave (Objectsender, MouseEventArgs e) {My. BorderBrush=NULL; My. BorderThickness=NewThickness (0.0); My. Opacity=1; }
In this case, run the program, when the mouse enters the button, the button will become translucent, and a red border appears
Issue where the background picture of a button disappears when you move the mouse over the button in WPF