5

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?

Андрей Про
  • 779
  • 2
  • 8
  • 15

3 Answers3

6

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" />
Shrinand
  • 351
  • 3
  • 5
3

You need to change the 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>
Herks
  • 897
  • 9
  • 25
0

Change the Build Action of button_picture.png to Resource if it is content. Also check the Copy to output directory property value

Manish
  • 510
  • 2
  • 12
  • I am not able to reproduce it. Can you provide more code which may be related to this button? – Manish Feb 26 '13 at 13:04