I've got a TabControl with several tabs and datatemplated listviews inside of them. I want to gain access to the listview (and scroll it to the top, I already know how to do that). The code I have gives me the listview of the tab that was selected before I clicked on the new tab. Any help would be awesome!
Here's what I have so far (Code attached to the SelectionChanged event of the TabControl).
private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e) {
if (!(e.OriginalSource is TabControl)) return; var contPres = FindVisualChild<ContentPresenter>(InspectionTabMain); var tc = e.OriginalSource as TabControl; var dataTemplate = contPres.ContentTemplate; if (dataTemplate == null) return; var lsv = (ListView)dataTemplate.FindName("ComponentDtls", contPres); if (lsv.Items != null && lsv.Items.Count > 0) { Console.WriteLine(lsv.Items.Count); lsv.ScrollIntoView(lsv.Items[0]); } }