【问题标题】:WPF WrapPanel Items don't scroll one by oneWPF WrapPanel 项目不会一一滚动
【发布时间】:2009-10-21 10:19:55
【问题描述】:

请有人帮帮我。

我在 ListBox ItemsPanelTemplate 中设置了 WrapPanel。另外,我已经设置了ScrollViewer.CanContentScroll="True"

但是为什么列表框项目没有逐项向上/向下滚动?滚动样式仍然是 PIXEL。

谁能帮帮我?

<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>

【问题讨论】:

    标签: wpf xaml wrappanel


    【解决方案1】:

    包装面板在设计时并未考虑到此功能(逻辑滚动)。您将需要创建一个派生自 wrappanel 类的新面板对象,然后实现 IScrollInfo 接口以实现您正在寻找的结果。

    【讨论】:

      【解决方案2】:

      我想我可能能够提供帮助,尽管我不确定你想要达到什么目的。你可以说得更详细点吗;您是否试图让每个 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 帮助,我发现这个网站非常好:www.YourCodeFactory.com

      【讨论】:

      • 感谢codeB10。我想实现逐项滚动图像的列表框滚动能力。这意味着我可以逐行滚动列表框项,而不是逐像素平滑滚动。您可以尝试在上面的代码中标记“”块并尝试逐项滚动。奇怪的是,当我添加 wrappanel 块时,列表框没有按项目滚动。
      • 嗨 - 真的很想帮忙。但是我仍然不确定您要达到的目标。如果您想逐行滚动 - 因此不需要包装面板。但是如果你想用未定义数量的图像填充每个项目,我认为列表视图的设置是错误的。无论哪种方式,请澄清您是否仍需要解决方案。另外,不知道你所说的逐像素平滑是什么意思,你到底指的是什么?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-01
      • 2017-12-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多