I'm having trouble getting the Source of my Image set in the code-behind. Here's my XAML:
<StackPanel Name="stkPanel" Height="1200" Width="478" HorizontalAlignment="Center" VerticalAlignment="Top" RenderTransformOrigin="0.723,0.509">
<Image Loaded="imgPicture_Loaded_1" x:Name="imgPicture" ImageOpened="ImgSelectedPicture_ImageOpened_1" Stretch="UniformToFill" Height="309" Width="413" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,30,0,0"></Image>
</StackPanel>
And the code-behind:
private void imgPicture_Loaded_1(object sender, RoutedEventArgs e)
{
imgPict = (sender as Image);
//ScrollViewer scroll = this.LayoutRoot.Children[2] as ScrollViewer;
imgPict.Source = new BitmapImage(new Uri("/project;component/Images/avatar.png", UriKind.RelativeOrAbsolute));
//bindPicture(imgPict);
}
Can anyone see what I'm doing wrong?
BuildActionof image you want to display is set to Resource? The way you are initializing the imageUriis suitable for embedded resources. And the best practice is to useContentasBuildActionfor images andUriinitialization will look likenew Uri("/Images/avatar.png", UriKind.Relative).