WPF - Scrollviewer 内的列表框不会滚动项目

标签 wpf xaml listbox scrollbar scrollviewer

我在 ListView 中有许多 UserControl。即使没有 ScrollViewer,WPF 也以某种方式实现了水平滚动。当我尝试实现垂直滚动时,ScrollViewer 是灰色的并且无法使用。我尝试将 ListView 包装在 ScrollViewer 中,但它不会滚动。 即使我删除了 ListView 并且只尝试在其中放置一个带有文本框的 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>

最佳答案

ListView/Listbox/Stackpanel : 可以根据内容的大小展开。

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

关于WPF - Scrollviewer 内的列表框不会滚动项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53412972/

相关文章:

wpf - 如何重复使用相同的控件两次但保持它们之间的状态

c# - WinRT Metro 中的 GridView 选择颜色

xaml - 状态栏主题仅在重新启动应用程序后更改

c# - 将 blob 和容器列出到列表框 C#

c# - 如何设置DataGridTextColumn的文字颜色?

c# - EntityFramework 6.0.0.0 读取数据,但不插入

c# - 将一个 View 数据上下文绑定(bind)到主窗口数据上下文

wpf - 从 View MVVM WPF在 View 模型中定义的访问枚举类型

wpf - 更新列表框而不丢失所选项目,WPF

arrays - 如何将列表框中的所有选定数据存储在VBA中的数组中