[英]how to bind dataSource to combobox?
I am trying to bind data with combobox but couldn't bind it. 我试图用combobox绑定数据但无法绑定它。
CBFolders.ItemsSource = client.GetNewsLetterFoldersAsync("token", 12, 3427).AsDataView();
In this code I am using web service which method GetNewsLetterFolders return data table. 在这段代码中,我使用Web服务,GetNewsLetterFolders方法返回数据表。
Please help me how I can bind this?? 请帮帮我怎么绑这个?
Return type of web service method should be a model class. Web服务方法的返回类型应该是模型类。 If it's returning
folderId
& Description
and both properties should member of FolderData
class. 如果它返回
folderId
& Description
,则两个属性都应该是FolderData
类的成员。 Hence FolderData essentialy become table. 因此FolderData必须成为表。
I consider service method GetNewsLetterFoldersAsync
returns List. 我认为服务方法
GetNewsLetterFoldersAsync
返回List。 So combox box should be bind like this 所以combox box应该像这样绑定
CBFolders.ItemsSource = await client.GetNewsLetterFoldersAsync("token", 12, 3427);
<ComboBox x:Name="CBFolders" SelectedValuePath="folderId" DisplayMemberPath="Description" />
SelectedValuePath
should be bind with that property which is needed while selection changes in ComboBox
. SelectedValuePath
应该与在ComboBox
选择更改时所需的属性绑定。 DisplayMemberPath
should be bind with that property which is needed to show in ComboBox
. DisplayMemberPath
应与要在ComboBox
显示的属性绑定。
CBFolders.SelectedItem
will return selected folderId
CBFolders.SelectedItem
将返回选定的folderId
You need to convert the datatable to List when you are binding it to ItemsSOurce property. 将数据表绑定到ItemsSOurce属性时,需要将数据表转换为List。 CBFolders.ItemsSource = client.GetNewsLetterFoldersAsync("token", 12, 3427).GetList().
CBFolders.ItemsSource = client.GetNewsLetterFoldersAsync(“token”,12,3427).GetList()。 Hope this helps.
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.