【发布时间】:2013-02-13 14:59:04
【问题描述】:
我正在尝试访问下面 XAML 中名为“ScrollViewerItems”的 ScrollViewer,并在后面的代码中使用它。该名称似乎无法识别,可能是因为它嵌入在 ItemsControl 中。我不需要命名访问,但是如何在后面的代码中访问 ItemsControl 的 ScrollViewer?
<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>
...
【问题讨论】:
-
你可以使用可视化树助手或者可以或者查询templatedchild
标签: wpf itemscontrol scrollviewer