在WPF Datagrid中填充组合框 [英] Populate Combobox in WPF Datagrid

查看:82
本文介绍了在WPF Datagrid中填充组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个功能

i have a function

public IEnumerable GetCountries()
{
XDocument oDoc = XDocument.Load("../../App_Xml/Country.xml");
var result = from info in oDoc.Descendants("Item")
select new CountryBO
 {
Code = Convert.ToString(info.Element("Code").Value),
Description = Convert.ToString(info.Element("Description").Value)
 };
return result;
}



我想用此功能返回的结果"填充组合框....
有人可以帮我吗...?

在此先感谢
Kunjammu



i want to populate my combobox with "result" returning from this function....
can anybody help me...?

Thanks in Advance
Kunjammu

推荐答案

为此使用CollectionSource.
实例化CollectionSource作为MVVM模型的一部分,并将getCountries分配给collectionsource的source属性.
另一种方法是在xaml中为collectionsource创建资源并为其命名.这样,将使用窗口或用户控件或任何您拥有的东西自动创建集合源.然后,您可以通过其名称访问collectionsource并再次分配source属性.
另一种更简单的方法是简单地枚举getCountries并填充组合框.但这实际上不是WPF的处理方式.
Use a CollectionSource to that.
Instantiate the CollectionSource as part of a MVVM model, and assign getCountries to the source property of the collectionsource.
Another way is to create a resource in your xaml for a collectionsource and give it a name. That way the collectionsource is automatically created with the window or user control or whatever you have. You can then get to the collectionsource via its name and assign the source property again.
Another even more simple way is to simply enumerate getCountries and fill the combobox. But this is not really the WPF way of doing things.


这篇关于在WPF Datagrid中填充组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆