wpf - 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>
解决方案
ListView/Listbox/Stackpanel :可以根据其内容的大小进行扩展。
将您的列表视图/列表框包装在高度为“*”的网格中(不要将“自动”用于高度属性,它会根据其内容使其像堆栈面板一样展开)
推荐阅读
- c# - 将项目移动到 .Net Core 5 后,Serilog 日志记录到 Azure eventthub 停止工作
- r - 如何添加从“日期”列生成的繁殖季节列
- http - 如何在 Visual Studio Code 之外下载 Business Central 应用程序的符号?
- postgresql - 我有这个使用 knex 的 sql 查询,我能够检索记录,但是在链接 OrderByRaw 时它没有正确排序
- javascript - 如何通过名为“fecha_proximo_mantenimiento”(next_date_maintenance)的字符串类型字段从集合中过滤文档?
- django - Django 管理屏幕不会让我看到每个模型下的条目列表
- java - 如何非顺序打印?
- ms-access - 错误“此表达式键入错误,或者它太复杂而无法计算。” 在使用日期字段进行查询
- mysql - 如何在我的 MySQL 中构建动态过滤查询
- python - TypeError:int 对象不可调用