0

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>
ASh
  • 34,632
  • 9
  • 60
  • 82
J-P
  • 403
  • 1
  • 6
  • 21

1 Answers1

4

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>
ASh
  • 34,632
  • 9
  • 60
  • 82
  • it works great but when I run the application I dont see the images, any thought – J-P Jul 19 '17 at 17:36
  • @J-P, see here: https://stackoverflow.com/questions/347614/wpf-image-resources - had to set the Image file to have a *build action* of Resource. – ASh Jul 19 '17 at 17:40
  • Thanks, I was able to fix it by changing the build action to resource – J-P Jul 19 '17 at 17:44