Search code examples
c#wpfimagebutton

Image in WPF Button not Visible at Runtime


I have the following XAML and my particular problem relates to the image that is to be displayed on the button

<Button  HorizontalAlignment="Right"  Grid.Row="1">
    <Image VerticalAlignment="Stretch" HorizontalAlignment="Stretch" 
           Height="16 " Width="16"  
      Source="pack://siteoforigin:,,,/Resources/UserCost2013Open16.png"
    />
</Button>

The image properties have Build Action = Resource, and Copy to output directory = Do not copy. The image shows in the designer but not at runtime.

How do I get the button image to appear at runtime?


Solution

  • Change the build action to Resource. Also your pack url is wrong. Either use:

    Source="pack://application:,,,/Resource/UserCost2013Open16.png"
    

    or simply

    Source="/Resource/UserCost2013Open16.png"