这是之前帖子的后续问题(here).
我有一些“标题”信息存储为:Dictionary<string,string>
- 其中第一个字符串代表字段名称,第二个字符串代表我想要显示的标题。
我有一组动态数据,存储为:Dictionary<string, object>
- 其中 string 是字段名称。
我在 xaml 中将其绑定为:
<data:DataGrid Name="_dataGrid" AutoGenerateColumns="True" IsReadOnly="False" Margin="5" Height="200">
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="Forename" CanUserSort="True" SortMemberPath="Forename"
Binding="{Binding Converter={StaticResource RowIndexConverter},
ConverterParameter=Forename}"/>
<data:DataGridTextColumn Header="Surname" CanUserSort="True" SortMemberPath="Surname"
Binding="{Binding Converter={StaticResource RowIndexConverter},
ConverterParameter=Surname}"/>
<data:DataGridTextColumn Header="Age" CanUserSort="True" SortMemberPath="Age"
Binding="{Binding Converter={StaticResource RowIndexConverter},
ConverterParameter=Age}"/>
<data:DataGridTextColumn Header="Shoesize" CanUserSort="True" SortMemberPath="Shoesize"
Binding="{Binding Converter={StaticResource RowIndexConverter},
ConverterParameter=Shoesize}"/>
</data:DataGrid.Columns>
</data:DataGrid>
问题1我想自动生成这些列(使用提供的标题信息)
问题2我希望根据数据类型生成列(即 boolean = checkbox)
问题3理想情况下,我还想通过数据绑定指定天气按钮是否应该存在于第一列中(即编辑/查看按钮)
我使用了一种遵循此伪代码模式的方法
columns = New DynamicTypeColumnList()
columns.Add(New DynamicTypeColumn("Name", GetType(String)))
dynamicType = DynamicTypeHelper.GetDynamicType(columns)
DynamicTypeHelper.GetDynamicType() 生成具有简单属性的类型。看这个帖子有关如何生成此类类型的详细信息
然后要实际使用该类型,请执行以下操作
Dim rows as List(Of DynamicItem)
Dim row As DynamicItem = CType(Activator.CreateInstance(dynamicType), DynamicItem)
row("Name") = "Foo"
rows.Add(row)
dataGrid.DataContext = rows
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)