The task is that when selecting item (the item is an image) from the listbox, the selected image is displayed in the image control.
For a start, I received a list of subfolders in which images are stored, this list is listed in the combobox
DirectoryInfo fillComboBox = new DirectoryInfo(path); var x = fillComboBox.GetDirectories(); foreach (var s in x) { cb1.Items.Add(s); } Then, choosing one of the received folders in the combobox, I fill the Listbox with the contents of this folder (image names),
if(cb1.SelectedItem.ToString() == namefolder) { var dir = new DirectoryInfo(path + @"\Image"); var files = dir.GetFiles("*.*"); lb1.ItemsSource = files; lb1.DisplayMemberPath = "Name"; } after that, when you click on item in the listbox, the selected picture should be displayed in image. At this point, there were problems, with collections of this type I do not quite understand how to work.
For example, if I do this way using ObservableCollection, I create a class in it with two fields and a constructor with two fields.
class CollectImg { public string path; public ImageSource resource; public CollectImg(string path, ImageSource resource) { this.path = path; this.resource = resource; } } then I define the collection
ObservableCollection<CollectImg> collect = new ObservableCollection<CollectImg> { };