简体   繁体   English

如果包含的项大于ListView本身,则WPF Scrollviewer不会在ListView中显示

[英]WPF Scrollviewer won't show in ListView if contains one item bigger then ListView itself

I have problem in my application where I have ListView with dynamic items. 我的应用程序中有带动态项目的ListView时出现问题。 Items might have variable height. 物品的高度可能可变。 In case there is a one item and its height is bigger than height of whole ListView, ScrollViewer won't show. 如果存在一项并且其高度大于整个ListView的高度,则ScrollViewer将不会显示。

Problem could be simplified in following example: 以下示例可以简化问题:

<Window x:Class="WpfApplication15.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow"
        Width="300"
        Height="200">
    <ListView Height="100" Margin="10">
        <ListViewItem Height="150" Background="LimeGreen">
            <TextBlock Text="ITEM" />
        </ListViewItem>
    </ListView>
</Window>

Why is that? 这是为什么? Is there anything I can do with it? 有什么我可以做的吗?

Try to set the VirtualizingPanel.ScrollUnit attached property to Pixel : 尝试将VirtualizingPanel.ScrollUnit附加属性设置为Pixel

<ListView Height="100" Margin="10" VirtualizingPanel.ScrollUnit="Pixel">
    <ListViewItem Height="150" Background="LimeGreen">
        <TextBlock Text="ITEM" />
    </ListViewItem>
</ListView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM