ScrollViewer 内的列表框
我不知道为什么这段代码工作正常:
<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 中的所有项目。有什么窍门呢?
I have no idea why this code works fine:
<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>
and this doesn't:
<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>
A ListBox version is unable to show all items in ScrollViewer. What is the trick?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该避免使用 ScrollViewer 来包装 ListBox,因为默认 ListBox 样式中已经存在 ScrollViewer。
You should avoid using a ScrollViewer to wrap a ListBox as there is already a ScrollViewer inside the default ListBox style.
只需更改列表框的模板即可
Just change template for ListBox