Button background image not displaying in WPF

I have a program in which I have many buttons. Each button has a background set like

<Button x:Name="mybutton" HorizontalAlignment="Left" Height="30" Margin="76,110,0,0" VerticalAlignment="Top" Width="25" Click="some_click"> <Button.Background> <ImageBrush ImageSource="Resource/button_picture.png"/> </Button.Background> </Button> 

The image is displayed as a background in .xaml when the program is not working, but when I launch the application image, there is no button in the background. How to debug this background in a button? Is there some stupid mistake that is?

+5
wpf xaml
Feb 26 '13 at 12:41
source share
3 answers

Make sure you have the following properties set directly in your script

1) Assembly action → Resource

2) Copy to output directory → Do not copy

3) Instead of using the relative path for the image source, try using the full path to the image like this (I say this because I don't know where the image resource is in your project, using the relative path perfectly normal in WPF)

 <Image Source="pack://application:,,,/AssemblyNameContainingImageResource;component/Resource/button_picture.png" /> 
+5
Feb 26 '13 at 13:49
source share

You need to change code like this

 <Button x:Name="mybutton" HorizontalAlignment="Left" Height="30" Margin="76,110,0,0" VerticalAlignment="Top" Width="25" Click="some_click"> <Image Source="Resource/button_picture.png"/> </Button> 
+3
Feb 26 '13 at 12:48
source share

Change the assembly action of button_picture.png to the resource, if it is content. Also check the Copy value to display the directory value

0
Feb 26 '13 at
source share



All Articles