c# - ListBox 中的 WrapPanel 具有水平和垂直滚动功能

标签 c# .net wpf vb.net xaml

根据https://stackoverflow.com/a/2573386/864101 ,我正在使用这段代码:

<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled">
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel HorizontalAlignment="Center" VerticalAlignment="Center" />
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
    <Image Source="http://placehold.it/50x50" Stretch="None"/>
    <Image Source="http://placehold.it/60x50" Stretch="None"/>
    <Image Source="http://placehold.it/70x50" Stretch="None"/>
    <Image Source="http://placehold.it/80x50" Stretch="None"/>
    <Image Source="http://placehold.it/90x50" Stretch="None"/>
    <Image Source="http://placehold.it/100x50" Stretch="None"/>
    <Image Source="http://placehold.it/600x200" Stretch="None"/>
</ListBox>

它是这样的:

我需要水平和垂直滚动条,就像这样(只是使用 HTML 的快速模型):

使用 ScrollViewer.Horizo​​ntalScrollBarVisibility="Disabled" 使图像换行,但禁用水平滚动条,这就是为什么我看不到 600x200 图像的其余部分.

我花了几个小时来解决这个问题,但没有运气,有人可以帮助我吗?

列表框中的图像根据用户输入的不同尺寸进行更新。

最佳答案

添加边距:

<ListBox>
<ListBox.ItemsPanel>
    <ItemsPanelTemplate>
        <WrapPanel MaxWidth="600" HorizontalAlignment="Center" VerticalAlignment="Center" />
    </ItemsPanelTemplate>
</ListBox.ItemsPanel>
<Image Margin ="5" Source="http://placehold.it/50x50" Stretch="None"/>
<Image Margin ="5" Source="http://placehold.it/60x50" Stretch="None"/>
<Image Margin ="5" Source="http://placehold.it/70x50" Stretch="None"/>
<Image Margin ="5" Source="http://placehold.it/80x50" Stretch="None"/>
<Image Margin ="5" Source="http://placehold.it/90x50" Stretch="None"/>
<Image Margin ="5" Source="http://placehold.it/100x50" Stretch="None"/>
<Image Margin ="5" Source="http://placehold.it/600x200" Stretch="None"/>
</ListBox>

也许您需要小于 5 的边距;你试一试。也许还有 600 的其他值。

关于c# - ListBox 中的 WrapPanel 具有水平和垂直滚动功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26833466/

相关文章:

c# - 使用 struct 强制验证内置类型的优缺点

c# - 以枚举为键绑定(bind)到字典中的值

c# - 你必须使用命令来遵循 MVVM 模式吗?

c# - WPF win8平板电脑模式键盘隐藏屏幕底部的项目

c# - 使用 XPath 查询从匹配的 XML 节点获取属性值

c# - 在不使用iF字的情况下,根据 bool 结果触发函数

c# - 如何使用c# ASP.net返回sql查询结果消息

c# - 如何从 XAML 中定义的 ResourceDictionary 检索 Brush 并将其应用于代码中的元素?

c# - 英文日期差异

.net - 使用 TPL 时如何管理线程本地存储 (TLS)?