首页 > 解决方案 > WPF - Scrollviewer 内的列表框不会滚动项目

问题描述

我在 ListView 中有许多用户控件。即使没有 ScrollViewer,WPF 也以某种方式实现了水平滚动。当我尝试实现垂直滚动时,ScrollViewer 是灰色且无法使用。我尝试将 ListView 包装在 ScrollViewer 中,但它不会滚动。即使我删除了 ListView 并且只尝试在其中放置一个带有 Textboxes 的 StackPanel,ScrollViewer 仍然被禁用。有什么我想念的吗?

XAML:

<ScrollViewer VerticalScrollBarVisibility="Visible" CanContentScroll="True" 
Grid.Row="1" Grid.Column="1">
            <ListBox Margin="0,0,10,10" ItemsSource="{Binding Feeder}" 
Grid.RowSpan="3">
             <ListBox.ItemContainerStyle>
                 <Style TargetType="{x:Type ListBoxItem}">
                     <Setter Property="Focusable" Value="False"/>
                 </Style>
            </ListBox.ItemContainerStyle>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <local:FeederControl FeederName="{Binding FeederName}" 
AxisList="{Binding AxisList}"></local:FeederControl>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
</ScrollViewer>

标签: wpfxamllistboxscrollbarscrollviewer

解决方案


ListView/Listbox/Stackpanel :可以根据其内容的大小进行扩展。

将您的列表视图/列表框包装在高度为“*”的网格中(不要将“自动”用于高度属性,它会根据其内容使其像堆栈面板一样展开)


推荐阅读