WPF包装物项不';不要一个一个滚动

WPF包装物项不';不要一个一个滚动,wpf,xaml,wrappanel,Wpf,Xaml,Wrappanel,谁来帮帮我 我在列表框ItemsPanelTemplate中设置了一个包装。另外,我已经设置了ScrollViewer.CanContentScroll=“True” 但是为什么列表框中的项目没有逐项上下滚动呢?滚动样式仍按像素显示 有人能帮我吗 <Grid> <ListBox x:Name="testListbox" ScrollViewer.CanContentScroll="True"> <ListBox.ItemsPanel>

谁来帮帮我

我在列表框ItemsPanelTemplate中设置了一个包装。另外,我已经设置了ScrollViewer.CanContentScroll=“True”

但是为什么列表框中的项目没有逐项上下滚动呢?滚动样式仍按像素显示

有人能帮我吗

<Grid>
    <ListBox x:Name="testListbox" ScrollViewer.CanContentScroll="True">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel Width="200" ScrollViewer.CanContentScroll="True"/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>


        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

        <ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
            <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/>
        </ListBoxItem>

    </ListBox>

</Grid>

我想我或许能帮上忙,尽管我不确定你到底想达到什么目的。你能说得更具体些吗;您是否试图使每个ListBoxItem都具有滚动功能(针对其内容)

由于无法将ScrollViewer添加到ItemPanelTemplate,您是否考虑过将ScrollViewer添加到各个ListBoxItems中:

例如:

<ListBoxItem Background="LimeGreen" BorderBrush="Black" BorderThickness="3" ScrollViewer.CanContentScroll="True">
                <ScrollViewer>
                    <Image Height="50" Width="80" ScrollViewer.CanContentScroll="True"/> 
                </ScrollViewer>
            </ListBoxItem>


对于更多的wpf/xaml帮助,我发现这个站点非常好:

包装器的设计没有考虑到这个特性(逻辑滚动)。您需要创建一个从wrappanel类派生的新面板对象,然后实现IScrollInfo接口,以获得所需的结果。

Thank codeB10。我想实现列表框滚动的能力,滚动图像逐项。这意味着我可以逐行滚动listboxitem,而不是按像素平滑滚动。您可以尝试在上述代码中标记“”块,然后尝试按项滚动。奇怪的是,当我添加wrappanel块时,listbox并没有按项滚动。嗨,我真的很想帮忙。但我仍然不确定你想要实现什么。如果要按行滚动,则不需要包装。但是如果您想用未定义数量的图像填充每个项目,我认为listview的设置是错误的。无论哪种方式,如果您仍然需要解决方案,请澄清。还有,我不确定你所说的像素是什么意思,你到底指的是什么?