Dynamic column binding in Xaml

后端 未结 1 1784
感情败类
感情败类 2021-01-14 21:15

This is a follow up question from an earlier post (here).

I have some \'header\' information stored as: Dictionary - where the firs

1条回答
  •  -上瘾入骨i
    2021-01-14 21:47

    I've used an approach that follows the pattern of this pseudocode

    columns = New DynamicTypeColumnList()
    columns.Add(New DynamicTypeColumn("Name", GetType(String)))
    dynamicType = DynamicTypeHelper.GetDynamicType(columns)
    

    DynamicTypeHelper.GetDynamicType() generates a type with simple properties. See this post for the details on how to generate such a type

    Then to actually use the type, do something like this

    Dim rows as List(Of DynamicItem)
    Dim row As DynamicItem = CType(Activator.CreateInstance(dynamicType), DynamicItem)
    row("Name") = "Foo"
    rows.Add(row)
    dataGrid.DataContext = rows
    

    0 讨论(0)
提交回复
热议问题