WPF项目控制滚动条
使用WPF项目控制滚动条,wpf,scrollbar,itemscontrol,Wpf,Scrollbar,Itemscontrol,使用ItemsControl在画布上显示项目集合。 问题是我看不到屏幕上的所有项目(需要使用滚动条),我已经签出并尝试了相同的方法,但对我无效,滚动条显示但被禁用。我的XAML: <Grid> <DockPanel> <ScrollViewer> <ItemsControl ItemsSource={Binding MyCollection}> <ItemsCon
ItemsControl
在画布上显示项目集合。
问题是我看不到屏幕上的所有项目(需要使用滚动条
),我已经签出并尝试了相同的方法,但对我无效,滚动条
显示但被禁用。我的XAML:
<Grid>
<DockPanel>
<ScrollViewer>
<ItemsControl ItemsSource={Binding MyCollection}>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
....
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</DockPanel>
</Grid>
....
与列表框不同,默认情况下,项控件的模板中没有ScrollViewer
去掉外部scrollViewer并将ItemsControl的模板设置为包含scrollViewer。另外,当您已经将ItemsControl包装到网格中时,我看不到DockPanel的任何用法
更改布局,如下所示:
<Grid>
<ItemsControl ItemsSource={Binding MyCollection}>
<ItemsControl.Template>
<ControlTemplate>
<Border
BorderThickness="{TemplateBinding Border.BorderThickness}"
Padding="{TemplateBinding Control.Padding}"
BorderBrush="{TemplateBinding Border.BorderBrush}"
Background="{TemplateBinding Panel.Background}"
SnapsToDevicePixels="True">
<ScrollViewer
Padding="{TemplateBinding Control.Padding}"
Focusable="False">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding
UIElement.SnapsToDevicePixels}"/>
</ScrollViewer>
</Border>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
....
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
....