Hi Guys,
I'm trying to select the ListBox item pro-grammatically. I'm selecting a particular image from Parent window and sending that image to the child window
So i'm sending the `ImageFileViewModel` to the child window (PhotoView) and I want to select this particular image in the ListBox loaded with the collection of images.
The below code i snet even getting the image count & not even getting into the `if`loops. How can i fix this? Thank you very much.
Code:
public PhotoView(ImageFileViewModel image) { InitializeComponent(); currImgHandler = new CurrentImageHandler(); imageListBox.Items.Clear(); DataContextChanged += OnDataContextChanged; string destination_dir = System.IO.Directory.GetCurrentDirectory() + @"./Prints/3.5x5"; ImageFileCollectionViewModel ImagesViewModel = new ImageFileCollectionViewModel(); ImageFileControler.CompleteViewList(ImagesViewModel, destination_dir); imageListBox.DataContext = ImagesViewModel; imageListBox.SelectedIndex = -1; for (int index = 0; index < imageListBox.Items.Count - 1; index++) { if (String.IsNullOrEmpty(image.ShortName)) { break; } if (imageListBox.Items[index].ToString() == image.ShortName) { imageListBox.SelectedItem = index; break; } } }