【问题标题】:How to Remove Spacing between ItemsControl Items如何删除 ItemsControl 项之间的间距
【发布时间】:2020-02-26 15:53:21
【问题描述】:

我有一个 ItemsControl,其中 MaterialDesign 芯片作为 DataTemplate。我的目标是一个接一个地放置物品,中间没有太多空间。

有一张现在的样子:https://imgur.com/hicWnGg.png

这是我的目标:https://imgur.com/0jIEk8k.png

我已经尝试过带有 Margin 的 ItemContainerStyle 但这并没有帮助我

我当前的代码

<ScrollViewer VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Auto">
                <ItemsControl x:Name="myItemsControl" Height="40" Margin="0 10 0 0">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <UniformGrid Rows="1"/>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>

                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <materialDesign:Chip Tag="{Binding Name}" Uid="{Binding SourceName}" Content="{Binding Code}" Width="75" IsDeletable="True" DeleteClick="Chip_DeleteClick"/>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </ScrollViewer>

【问题讨论】:

  • 尝试使用StackPanelOrientation=Horizontal 而不是UniformGrid
  • UniformGrid 将始终根据其宽度将项目隔开,使用上面建议的 StackPanel。
  • 谢谢各位!这就是我一直在寻找的
  • @Mitya 请用实际答案而不是 cmets 回答问题。否则,任何人都无法受益。

标签: c# wpf itemscontrol


【解决方案1】:

将您的 ItemsPanelTemplate 更改为 StackPanel 而不是 UniformGrid

<ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
        <StackPanel Orientation="Horizontal"/>
    </ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

【讨论】:

    猜你喜欢
    • 2015-11-24
    • 2019-06-13
    • 2015-01-20
    • 1970-01-01
    • 2017-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-08
    相关资源
    最近更新 更多