I currently have a class object that is bound to a listboxitem. Before I used to get the other objects inside the ListBoxItem
by clicking a button and accessing its parent, but now I need to gather the objects without clicking the buttons or labels, just by its class.
I've tried to gather the ListBoxItem
with its index and its class binding, but both of them is giving me a null
value:
ObservableCollection<ClassBinding> classList = new ObservableCollection<ClassBinding>();
... adding items here to the collection;
listBox.ItemsSource = classList;
ListBoxItem lbi = (ListBoxItem)listBox.ItemContainerGenerator.ContainerFromIndex(index);
Is there another way to access the listboxitem to later gather the other objects by using the function FindName(...)
?
Debug:
TextBlock delay = lbi.FindName("lblDelay") as TextBlock;
Error:
Output: Exception thrown: 'System.InvalidOperationException' in WindowsBase.dll