I have a PivotControl that contains ListBox elements:
<controls:Pivot Title="SECTIONS" x:Name="pivotControl" ItemsSource="{Binding SectionViewModels}">
<controls:Pivot.HeaderTemplate>
<!-- -->
</controls:Pivot.HeaderTemplate>
<controls:Pivot.ItemTemplate>
<DataTemplate>
<StackPanel>
<!-- if you don't explicitly specify the height, the scrolling won't work -->
<ListBox ItemsSource="{Binding StoryViewModels}" SelectionChanged="StoryList_SelectionChanged"
Height="625" u:ScrollViewerMonitor.AtEndCommand="{Binding ElementName=LayoutRoot, Path=DataContext.FetchMoreDataCommand}">
<ListBox.ItemTemplate>
<DataTemplate>
<local:StoryControl />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</DataTemplate>
</controls:Pivot.ItemTemplate>
</controls:Pivot>
I want to get and set the ScrollViewer.VerticalOffset of a ListBox corresponding to a given SectionViewModel (which is the item source of the pivot control). How can I do this?
There’re some cases that you need to access view elements. For those cases using the VisualTreeHelper is the solution. You can find a summary of it in my blog and some helper extension methods.
I recommend to use SilverlightSpy to see how the VisualTree is composed at runtime and be able to more efficiently navigate it.