Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Background Image of Button not showing in WPF

Tags:

wpf

xaml

I have program in which I have lots of buttons. Each of button has background set as

  <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>

Image is showing as background in .xaml when program not running but when i run application image is not there as background of button. How do i debug this background in button ? Is there any goofy error that is there?

like image 693
Андрей Про Avatar asked Feb 26 '13 12:02

Андрей Про


1 Answers

Let's make sure we have the following properties set right in your scenario

1) Build Action -> Resource

2) Copy to Output Directory -> Do not copy

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

<Image Source="pack://application:,,,/AssemblyNameContainingImageResource;component/Resource/button_picture.png" />
like image 140
Shrinand Avatar answered Nov 15 '22 03:11

Shrinand