如何对齐 ItemsControl 控件 (WPF) 的列
我在 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
I have defined a ItemsControl control in xaml as follows:
<ItemsControl BorderThickness="0" Name="SummaryList">
</ItemsControl>
In the same xaml file, I've defined the following DateTemplate for each item in the ItemsControl:
<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>
I have bound the ItemsControl's ItemSource to a generlic list of UpgradeItems (i.e. List) and programmatically add to this list during execution. The items in the ItemsControl control populate correctly except that the data in the columns are not aligned. How can I modify this so that the three separate columns (ItemText, FromVersion and ToVersion) are aligned?
TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够在网格上使用 SharedSize 组,但是我觉得有更好的方法来做到这一点。这是有关该主题的链接: http://blogs.microsoft.co.il/blogs/guy/archive/2009/06/30/wpf-grid-shared-size-groups.aspx
You should be able to use a SharedSize groups on grids, however I feel there is a better way to do this. Here's a link on the subject: http://blogs.microsoft.co.il/blogs/guy/archive/2009/06/30/wpf-grid-shared-size-groups.aspx
造成这个问题的部分原因是
ItemsControl
没有“列”:控件本身不知道其项目的内容如何相对于每个项目进行布局。其他。您最好的选择可能是使用支持柱状数据的 ItemsControl 子类之一,例如 ListView/GridView 或成熟的 DataGrid。
Part of what makes this tricky is that the
ItemsControl
doesn't have "columns": the control itself has no idea how its items' contents are laid out in relation to each other.Your best bet would probably be to use one of the subclasses of ItemsControl that does support columnar data, such as ListView/GridView or the full-fledged DataGrid.