How can I get all the ScrollContentPresenter in a ListView in CSharp source code?

Dear All

I want to get all the ScrollContentPresenter a ListView in CSharp source,not XAML.

Unfortunately, I can get it by use the member variables of the listview instance.

Should it be a member variable of listview instance? or a member variable of its member variable?

Thanks~~~~~

The visual tree is dumped as following(partial):

ScrollViewer

Grid

DockPanel

ScrollViewer

Grid <-- here is the header of listview

ScrollContentPresenter < I want to get this

ItemPresenter

VisualizingStackPanel

ListViewItem <-- This ListViewItem is related to the row in ListView

ListViewItem

ListViewItem

ListViewItem

ListViewItem

AdornerLayer

ScrollerBar

ScrollerBar

DockPanel

Sincerely

[970 byte] By [StrongZhu] at [2008-1-7]
# 1

Hello, suppose you haven’t modified the default ControlTemplate. You can use something like this:

ScrollViewer sv = (ScrollViewer)(VisualTreeHelper.GetChild((Border)VisualTreeHelper.GetChild(listView1, 0), 0));

ScrollContentPresenter scp = (ScrollContentPresenter)sv.Template.FindName("PART_ScrollContentPresenter", sv);

The first child in the default template of ListView is a Border whose first child is a ScrollViewer that contains the ScrollContentPresenter. Since the ScrollViewer doesn’t have a name, you’ll have to use VisualTreeHelper to get it. If you’re writing your own template, you can simply give the ScrollViewer a name so you can easily use FindName to find it.

Yi-LunLuo-MSFT at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified