gpt4 book ai didi

c# - 使用具有行+列坐标的值集合动态填充数据网格

转载 作者:行者123 更新时间:2023-12-03 10:44:48 24 4
gpt4 key购买 nike

我有一个包含三个字段的可观察集合:

单元格值、列索引、行索引

(编辑:列表的每个对象都有这三个字段)

有没有办法可以使用列索引和行索引将此可观察集合绑定(bind)到数据网格以指定每个单元格的位置?如果有帮助,可观察集合按列顺序排列(第一个对象是 [row 1, col 1],第二个对象是 [row 1, col 2] 等)。

重要的是它遵循导致我出现问题的 MVVM 模式。

最佳答案

您可能想看看 UniformGrid .您可以绑定(bind)到RowsColumns告诉它你的尺寸(你的 View 模型的属性)。然后围绕 ItemsControl 构建并通过 ItemsSource 输入您的数据.剩下的就是关于造型(你想让你的 table 看起来怎么样)。以下 XAML 可能会为您提供一个起点。 MyList这里只是一个列表int供测试用。

    <ItemsControl ItemsSource="{Binding MyList}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="{Binding Rows}" Columns="{Binding Columns}"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

关于c# - 使用具有行+列坐标的值集合动态填充数据网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31520854/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com