Reputation: 339
I'm developing a Windows Phone app.I have an image . This is its XAML code:
<Image x:Name="imageclock" Grid.Row="1"
Source="Image/Myimage.png" Height="240" Width="240"
/>
And i want change image.source with this code:
private void ClickonBtn(object sender, EventArgs e)
{
BitmapImage bm = new BitmapImage(new Uri("Image/Darktheme.png", UriKind.RelativeOrAbsolute));
imageclock.Source = bm;
}
But when i complied, imageclock.Source=Null and this is error:
An exception of type 'System.NullReferenceException' occurred in Newappver1.DLL but was not handled in user code
Upvotes: 6
Views: 21295
Reputation: 1326
imageclock.Source = new BitmapImage(new Uri("ms-appx:///Image/Darktheme.png"));
source https://msdn.microsoft.com/library/windows/apps/windows.ui.xaml.controls.image.source.aspx
Upvotes: 0
Reputation: 500
Your code looks ok but maybe you need to add @
before the image path to handle the /
in the code behind like this :
BitmapImage bm = new BitmapImage(new Uri(@"Image/Darktheme.png", UriKind.RelativeOrAbsolute));
Upvotes: 7