I'm having the same problem and I tried the solution above but it doesn't seem to do anything for me. My Image is being loaded from a Stream, instead of a URL. Has anyone gotten this to work? Here is the code I'm working with:
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.EnableMultipleSelection = true;
fileDialog.Filter = "Images (.jpg, .jpeg, .png)|*.jpg;*.jpeg;*.png";
if (DialogResult.OK == fileDialog.ShowDialog())
{
try
{
foreach (FileDialogFileInfo info in fileDialog.SelectedFiles)
{
BitmapImage bimg = new BitmapImage();
using (Stream str = info.OpenRead())
{
bimg.SetSource(str);
}
images.Add(bimg);
Image img = new Image();
img.Source = bimg;
img.Cursor = Cursors.Hand;
img.Margin = new Thickness(2);
img.MaxWidth = 107;
imgList.Items.Add(img);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
//txtImageCount.Text = imgList.Children.Count.ToString() + " Images";
}
then...
private void imgList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
Image img = ((Image)e.AddedItems[0]);
BitmapImage bmp = (BitmapImage)img.Source;
imgMain.Source = new BitmapImage(bmp.UriSource);
imgMain.Visibility = Visibility.Visible;
}
catch (Exception ex)
{
}
btnDelete.IsEnabled = true;
}
No exceptions get thrown or anything, it just simply does nothing when the SelectionChanged event fires. If I step through it, that code is being called but nothing happens.
Thanks!