WPF ItemsControl增加滚动条
ItemsControl是一个基础类型,控件本身没有内置滚动条,如果不太想用ListBox的默认样式,可以自己增加一个滚动条,代码如下:
<ItemsControl Height="365" ItemsSource="{Binding ...}" BorderThickness="0" Margin="0 5 0 5">
<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl">
<ScrollViewer x:Name="ScrollViewer" Padding="{TemplateBinding Padding}" Template="{StaticResource NewScrollViewer}">
<ItemsPresenter/>
</ScrollViewer>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="15 5 0 5">
<CheckBox Foreground="#3E3E42" Width="60" VerticalAlignment="Center" IsChecked="{Binding IsChecked}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>