I’m trying to access the ScrollViewer named ‘ScrollViewerItems’ in the XAML below and use it in code behind. The name doesn’t seem to be recognized, likely because its embedded in the ItemsControl. I don’t need the named access, but how to I get to the ItemsControl’s ScrollViewer in code behind?
<ItemsControl x:Name="EnteredItemsView" ItemsSource="{Binding LineItems}" VirtualizingStackPanel.IsVirtualizing="True" ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.Template>
<ControlTemplate>
<ScrollViewer x:Name="ScrollViewerItems" Focusable="False">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
</ScrollViewer>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemTemplate>
...
The ScrollViewer is the visual child of the ItemsControl:
Note that the ItemsControl must have been loaded before you can access the child.
You may add a
Loadedhandler to the ItemsControlwhere you access the ScrollViewer