Reputation: 705
I am new to C# and WPF and was trying to make a very basic program that show a picture. So in the XAML file I put in this code:
<Image HorizontalAlignment="Left" Height="100" Margin="184,143,0,0"
VerticalAlignment="Top" Width="100" Source="image.jpg"/>
It shows up in the editor (Visual Studio) but when I run the program is appears to be gone! Here is the entire code:
<Window x:Class="Follow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Image HorizontalAlignment="Left" Height="100" Margin="184,143,0,0"
VerticalAlignment="Top" Width="100" Source="bp.jpg"/>
</Grid>
</Window>
Thanks for your help, I've been looking but can't seem to find the answer!
Upvotes: 1
Views: 3432
Reputation: 1639
Try this
Source="pack://application:,,,/bp.jpg"
If your image in some folder then use:
Source="pack://application:,,,/FolderName/bp.jpg"
If the image is in your resources
folder and its buid action
is set to Resource
. You can reference the image in XAML
as follows:
Source="pack://application:,,,/Resources/bp.png"
Upvotes: 2