Reputation: 57
I've created an image button via xaml:
<Button x:Name="btnAdd5" Grid.Column="12" Grid.Row="6" Visibility="Visible" >
<Image Source="/MyApp;component/Images/Icons/add-icon.png" />
</Button>
At the xaml designer, everything is fine, but during the Debug Mode I do only see a little dot.
What did I do wrong?
Upvotes: 0
Views: 5458
Reputation: 1
If you are using Visual Studio, you must ALSO add the images to your project file or you will get exactly the behavior you describe. For example, I created an Icons Folder inside my project and separately moved all the icons (.png format) into the folder. EPIC fail! The preview worked fine, however when running the executable the icons were not visible. Apparently they are not added as resources in your executable unless you add a specific reference in your VS project file. Again, preview will work... but that turns out to be a monstrous red herring when troubleshooting the issue. Cost me about 4 hours to resolve!
For each Icon I wanted to use, I had to click the project folder inside VS, say "add existing item" and then pick the right file. Here's what you should see in your .csproj file:
<ItemGroup>
<Resource Include="Icons\cut.png" />
<Resource Include="Icons\page_copy.png" />
<Resource Include="Icons\page_paste.png" />
<Resource Include="Icons\text_bold.png" />
<Resource Include="Icons\text_italic.png" />
<Resource Include="Icons\text_underline.png" />
</ItemGroup>
Upvotes: -1
Reputation: 3318
Try to put the image as below :
<Button>
<Button.Template>
<ControlTemplate>
<Image Source="/MyApp;component/Images/Icons/add-icon.png" x:Name="btnAdd4I" Visibility="Visible" Stretch="Fill" />
</ControlTemplate>
</Button.Template>
</Button>
Upvotes: 2