Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

tabcontrol and listview content - selecting the currently selected tab's listview

$
0
0

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]); } }



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>