【问题标题】:Silverlight 3 Dataform - how to add fieds at runtimeSilverlight 3 Dataform - 如何在运行时添加字段
【发布时间】:2009-11-15 05:32:25
【问题描述】:

我正在从动态数据创建一个 DataForm(所以我不能在 xaml 中创建列),我目前为我的 DataGrid 创建列(我还没有弄清楚如何在一个列中创建一个按钮 + 事件)

foreach (var item in headings.Entities)
                    {
                        theDataGrid.Columns.Add(
                            new DataGridTextColumn
                            {
                                Header = item.Label,
                                Binding = new Binding(item.LocalName)
                            });
                    }

我看不到任何在运行时向 DataForm 添加字段的方法,但是...

【问题讨论】:

    标签: silverlight runtime field dataform


    【解决方案1】:

    最好不要在代码中创建数据网格列,而是使用绑定。只需将数据网格绑定到 headings.Entities 集合。

    与您的 DataForm 相同,只需将您的项目绑定到它,它就会为您创建所有正确的字段。

    【讨论】:

    • 是的,有道理。我只需要弄清楚如何分别绑定标题和数据(即标题与绑定字段名称不同)
    • 在属性上使用 DisplayAttribute 并将名称放入其中。
    • 谢谢,我在这里发布了一个更具体的后续问题:stackoverflow.com/questions/1753187/…
    猜你喜欢
    • 1970-01-01
    • 2011-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-02
    • 1970-01-01
    • 1970-01-01
    • 2015-12-29
    相关资源
    最近更新 更多