我不知道为什么这段代码工作正常:
<ScrollViewer Height="674" HorizontalAlignment="Left" VerticalAlignment="Top" Width="480" Margin="0,94,0,0" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden">
<StackPanel>
<Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
<Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
<Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
<Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
<Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
<Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
<Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
<Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
<Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
<Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
<Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
<Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
<Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
<Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
<Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
</StackPanel>
</ScrollViewer>
而这不会:
<ScrollViewer Height="674" HorizontalAlignment="Left" VerticalAlignment="Top" Width="480" Margin="0,94,0,0" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden">
<ListBox Width="480" ItemsSource="{Binding ViewModel_ObservableCollection_Property_With_15_Items}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Height="85">
<Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
ListBox 版本无法在 ScrollViewer 中显示所有项目。诀窍是什么?
最佳答案
您应该避免使用 ScrollViewer 来包装 ListBox,因为默认 ListBox 样式中已经有一个 ScrollViewer。
关于.net - ScrollViewer 中的列表框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7947657/