- Create sub-directory for resources called say "Resources"
- Add your resources (images, icons etc.) to it.
- Copy the folder structure into the VS project and add the resource files to it.
- Check the Properties of your resources in VS project file to ensure they have a Build Action of 'Resource'
<Image Source="Resources/P4.ico" />Adding an image to a window's resources is very easy:
<Window.Resources> <Image x:Key="P4Icon" Source="Resources/P4.ico" /> </Window.Resources>In code:
Image myImage = new Image();Inserting an image in a button is very easy in WPF:
myImage.Source = new BitmapImage(new Uri("Icons/MyImage.png", UriKind.Relative));
<Button HorizontalAlignment="Left" Margin="5,8,0,10" Name="p4But" Width="34" Click="p4But_Click"> <Image Source="Resources/P4.ico" Width="24" /> </Button>