我在 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/