I'm currently trying to update a program by having a button (nextImg) that when clicked calls a function that creates two bitmaps, generates a number starting from 0, and increments every time the nextImg button gets clicked. Then the program takes that number(num) and returns a string from a List[num] which has all the Uri sources of my photos. However when I click next image I get a
System.NullReferenceException.
private void Image_Loaded(object sender, RoutedEventArgs e)
{
// Create a new BitmapImage.
BitmapImage b = new BitmapImage();
BitmapImage b1 = new BitmapImage();
Image img = new Image();
string sSrc = numGen();
b.BeginInit();
b.UriSource = new Uri(sSrc);
b.EndInit();
b1.BeginInit();
b1.UriSource = b.UriSource;
b1.EndInit();
img = sender as Image;
img.Source = b; // Error on this line
Canvas1.Height = Picturebox1.Height;
Canvas1.Width = Picturebox1.Width;
Canvas1.Margin = Picturebox1.Margin;
}