J-P
J-P

Reputation: 403

WPF Button Image is not showing when I set it to the foreground

I have a Button that I need to have a colored Background but on top of the color I need to have an image. I did add background color and added the image in the foreground. The image is not showing at all as soon I added to the foreground.

If I add image to the Background it will appear. Any idea?

<Button x:Name="btnInkMode" Content="" Height="20" VerticalAlignment="Top" IsEnabled="True" HorizontalAlignment="Left" Width="20" Canvas.Left="554" Canvas.Top="5" Click="btnInkMode_Click" Background="#FFFFD56A">
    <Button.Foreground>
        <ImageBrush ImageSource="../Resources/pen-icon.gif"/>
    </Button.Foreground>
</Button>

Upvotes: 0

Views: 1136

Answers (1)

ASh
ASh

Reputation: 35733

Foreground is a color of text. Since Content is an empty string, Foreground is irrelevant (there is nothing to display in that color).

Add Image as Content:

<Button x:Name="btnInkMode" Height="20" VerticalAlignment="Top" IsEnabled="True" HorizontalAlignment="Left" Width="20" Canvas.Left="554" Canvas.Top="5" Click="btnInkMode_Click" Background="#FFFFD56A">
    <Button.Content>
        <Image Source="../Resources/pen-icon.gif"/>
    </Button.Content>
</Button>

actually you don't even need to write <Button.Content> tag. Above and below code are equivalent:

<Button x:Name="btnInkMode" Height="20" VerticalAlignment="Top" IsEnabled="True" HorizontalAlignment="Left" Width="20" Canvas.Left="554" Canvas.Top="5" Click="btnInkMode_Click" Background="#FFFFD56A">
    <Image Source="../Resources/pen-icon.gif"/>
</Button>

Upvotes: 4

Related Questions