2
这是以前发布的跟进问题(here)。Xaml中的动态列绑定
我有一些“标题”信息存储为: 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我想要的列可基础上产生它们是什么数据类型(即,布尔=复选框)
问题3理想我WOU ld还想指定一个按钮应该存在于第一列还是不存在(即通过数据绑定
显然有很多的细节忽略了这种解释的细节,但它应该设置你在正确的道路上。 – kenwarner 2009-11-18 02:27:44
啊,是的 - 我已经研究过弗拉基米尔博杜洛夫的方法。这真的很酷。但是,我的问题是,动态类型生成意味着您不能在设计时使用强类型(并且运行时调试返回null)。 科林在这里有一个很好的帖子:http://www.scottlogic.co.uk/blog/colin/2009/04/binding-a-silverlight-datagrid-to-dynamic-data-via-idictionary/comment-page- 1 /#comment-5535 这解释了一种更“标准”的做事方式。使用不同的控件时需要进行一些调整,但c#代码是非常优雅的解决方案。 – 2009-11-18 21:45:32