Cheburek
Cheburek

Reputation: 2113

wpf button image runtime invisible

Can't figure out why in runtime image on button is not visible. At the same time in design mode it looks fine. Also tried to remove Stretch, set Height and Width for image, change image to jpg/png, change Source to "ProjectName,component" enter image description here

Upvotes: 0

Views: 2249

Answers (2)

Cheburek
Cheburek

Reputation: 2113

When images were added to project resources Visual Studio set Build Action to None for such files...

  1. Set Build Action to Resource
  2. Change source to /Resources/filename.png
  3. Set the size for the parent object
  4. Set Stretch for image

See working snippet

<Button x:Name="BtName" Click="Bt_Click" Height="35" Width="35">
   <Image Source="/Resources/Button-Turn-Off-icon.png" Stretch="Fill" />
</Button>

Upvotes: 1

DotNetRussell
DotNetRussell

Reputation: 9857

You need to set the Build Action to Resource, set always copy and add the image to the bin\debug (and release if you are using it) files. Some times VS doesn't bring it in and I don't know why but I had the same problem recently.

Upvotes: 0

Related Questions