阵列上的Datagrid绑定的XAML by位置 [英] Array binding Xaml by Position on Datagrid

查看:102
本文介绍了阵列上的Datagrid绑定的XAML by位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有字符串数组作为输入的列表。数组维度是静态的所有列表中,但我不知道数组的大小,直到列表被检索。
我需要绑定在Silverlight中的一个DataGrid的列表中。

I have a list of string array as input. The array dimension are static for all the list but I can't know the array size until the list is retrieved. I need to bind the list in a datagrid in Silverlight.

我试图在运行时创建列,每列绑定到特定阵列的位置,但不能找到一种方式。

I tried to create columns at runtime, binding each column to a particular array position but cannot find a way.

你有什么想法怎么办呢?

Have you any idea how to do it?

我最终可以转换我的数组列表中的其他任何可能在DataGrid被绑定?

I could eventually "convert" my list of array in anything else that could be binded in a datagrid?

这个想法是有一种二维矩阵在Silverlight中的数据网格中显示(我认为这个问题是相似的)。

The idea is to have a sort of 2d Matrix showed inside the datagrid in Silverlight (I think that the problem is similar).

列表

 column_1      column_2       column_3   ..   column_m

string[1,1]   string[1,2]    string[1,3] ..  string[1,m]
string[2,1]   string[2,2]    string[2,3] ..  string[2,m]
string[3,1]   string[3,2]    string[3,3] ..  string[3,m]
....
string[n,1]   string[n,2]    string[n,3] ..  string[n,m]

n是列表lenght,m为列表列最大数。

n is list lenght, m is list column max number.

任何想法是pciated AP $ P $

Any idea is appreciated

推荐答案

不幸的是不是要容易。

你有任何有效的制约,就像是允许的或类似的东西列的最大值是多少?
如果你(假设你有N条列最大值),你也许可以做一些事情通过

Do you have any valid constraints, like the maximum number of columns that is allowed or anything like that? If you do (let's say you have N column maximum), you might be able to do something by


  1. 有暴露N A类
    属性(命名为COL1 ...为科隆
    例子),该映射内容
    该阵列在列一行的
    X

  2. 生成该类的列表中,
    每行一个实例

  3. 生成正确数量的
    飞柱,结合各
    列财产COLX

  4. 绑定您的DataGrid到列表

这有点难看,但它会工作。

That's kind of ugly, but it would work.

如果你没有依靠DataGrid中,有一种使用UniformGrid的可能性。一个UniformGrid是布局其子规则的网格(每个项目有相同的宽度,每个项目有相同的高度)的面板。可以在运行时指示列数,与面板将适合孩子一前一后到的列数,然后继续在另一线路上。
你可以一个ItemsControl绑定到你的数组,表示它不应该使用UniformGrid作为其布局面板,并表示合适的ItemTemplate来呈现每个字符串。

If you do not have to rely on the DataGrid, there is a possibility using a UniformGrid. A UniformGrid is a panel that layouts its children in a regular grid (every item has the same width, every item has the same height). You can indicate the number of columns at runtime, and the panel will fit children one after the other up to the number of columns and then continue on another line. You could bind an ItemsControl to your array, indicating it should use a UniformGrid as its layout panel and indicating a suitable ItemTemplate to render each string.

第二个选项是很容易的,但你不会有这样的排序,移动列,行选择,每行等版本的事件DataGrid的能力。

The second option is much easier, but you will not have the capabilities of the DataGrid like sorting, moving columns, row selection, edition events per row etc.

这篇关于阵列上的Datagrid绑定的XAML by位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆