Dotnet Dotnet - 1 month ago 10
C# Question

WPF issue with button background image

I have my wpf button as follows

<Button x:Name="helpButton" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="552,201,95,726" Width="32" Height="32" BorderThickness="0" Click="helpButton_Click">
<Button.Background>
<ImageBrush ImageSource="/Images/help-icon1.png"></ImageBrush>
</Button.Background>
</Button>


On window load I am able to see the image perfectly but when I hover the mouse I am not able to see the image

enter image description here

So can some one help me

Jim Jim
Answer

A more sensible approach to start would be by using <Button.Template> instead of <Button.Background>

<Button x:Name="helpButton">
    <Button.Template>
        <ControlTemplate>
            <Border HorizontalAlignment="Center" VerticalAlignment="Center" >
                <Image Source="/Images/help-icon1.png" Width="32" Height="32"/>
            </Border>
        </ControlTemplate>
     </Button.Template>
</Button>
Comments