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