我希望有人可以幫助我或發佈一個鏈接到相關的問題,這將有答案。我已閱讀他們大多數,這就是我如何得到這麼遠...wpf datagrid組合框綁定staticresource keyvalue對列表
所以我有一個3列datagrid,其中兩個綁定到一個數據表和第三個是一個comboboxcolumn應綁定到另一個。
我把combobox列綁定到一個靜態資源。
我不理解如何將數據錶轉換爲我想用作我的combobox列的靜態資源的keyvalue對列表。
public class MyClasificators:List<KeyValuePair<object, object>>
{
public MyClasificators()
{
this.Add(new KeyValuePair<object, object>(1, "Test"));
this.Add(new KeyValuePair<object,object>(2, "Test1"));
this.Add(new KeyValuePair<object, object>(3, "Test2"));
}
}
XAML:
<local:MyClasificators x:Key="clList"></local:MyClasificators>
組合框柱:
<dg:DataGridTemplateColumn Header="test">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{StaticResource clList}" DisplayMemberPath="Value"/>
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
現在這工作正常,但我怎麼通過這個表來MyClassificators類,我如何將其轉換爲列表> :
DataTable country = new DataTable();
country.Columns.Add(new DataColumn("id_country", typeof(int)));
country.Columns.Add(new DataColumn("name", typeof(string)));
DS.Tables.Add(country);
因此,您想將MyClassificator的內容放入DataTable中? –
沒有其他的方式。我想把Datatable的所有條目都放到MyClassificator中。 – acosta