【问题标题】:How to align the columns of an ItemsControl control (WPF)如何对齐 ItemsControl 控件 (WPF) 的列
【发布时间】:2011-05-04 15:37:19
【问题描述】:

我在 xaml 中定义了一个 ItemsControl 控件,如下所示:

<ItemsControl BorderThickness="0"  Name="SummaryList">
</ItemsControl>

在同一个 xaml 文件中,我为 ItemsControl 中的每个项目定义了以下 DateTemplate:

<DataTemplate DataType="{x:Type app:UpgradeItem}">
    <StackPanel Orientation="Horizontal">
        <Label Margin="5,5" Content="{Binding Path=ItemText,Mode=OneTime}" />
        <Label Margin="5,5" Content="{Binding Path=FromVersion,Mode=OneTime}" />
        <Label Margin="5,5" Content="{Binding Path=ToVersion,Mode=OneTime}" />
    </StackPanel>
</DataTemplate>

我已将 ItemsControl 的 ItemSource 绑定到 UpgradeItems 的通用列表(即列表),并在执行期间以编程方式添加到此列表中。 ItemsControl 控件中的项目会正确填充,但列中的数据未对齐。如何修改它以使三个单独的列(ItemText、FromVersion 和 ToVersion)对齐?

TIA

【问题讨论】:

    标签: c# wpf wpf-controls itemscontrol


    【解决方案1】:

    您应该能够在网格上使用 SharedSize 组,但是我觉得有更好的方法来做到这一点。这是关于该主题的链接:http://blogs.microsoft.co.il/blogs/guy/archive/2009/06/30/wpf-grid-shared-size-groups.aspx

    【讨论】:

      【解决方案2】:

      使这个问题变得棘手的部分原因是ItemsControl 没有“列”:控件本身不知道其项目的内容是如何相互关联的。

      您最好的选择可能是使用支持列数据的 ItemsControl 子类之一,例如 ListView/GridView 或成熟的 DataGrid

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-08-23
        • 2015-10-25
        • 1970-01-01
        • 1970-01-01
        • 2010-11-05
        • 1970-01-01
        • 2012-02-23
        • 2021-08-08
        相关资源
        最近更新 更多