How to display Bitmap Image in image control on WPF using C#
10,097
They key is to retrieve the row index that was clicked, and get the image URL for that row. Since you say you are clicking on the row, this can be done in a method similar to that below
private void ListViewEmployeeDetails_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
DataRow row = (DataRow)sender; //Get the row that was clicked
string imageURL = row["imageUrl"].ToString();//Get the img URL for that row
ImageSource imageSource = new BitmapImage(new Uri(imageURL));
image1.Source = imageSource;
}
Hope this helps
Author by
Admin
Updated on June 04, 2022Comments
-
Admin almost 2 years
I want that when I double click on a row in
ListView
, it should display theImage
corresponding to that row. This row also contains the path of theImage
.I tried the following but it displays the same
Image
for all rows because I have given the path for a specificImage
:private void ListViewEmployeeDetails_MouseDoubleClick(object sender, MouseButtonEventArgs e) { ImageSource imageSource = new BitmapImage(new Uri(@"C:\northwindimages\king.bmp")); image1.Source = imageSource; }
Please suggest something.