如何在WPF .Net4.0中设置ComboBox的SelecteItem [英] How to set SelecteItem of ComboBox in WPF .Net4.0

查看:51
本文介绍了如何在WPF .Net4.0中设置ComboBox的SelecteItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许您知道ComboBox具有SelectedItem.

此组合框具有此项itemSource(1、2、3、4).

而且我想设置任何内容(1或2).

如果我使用SelectedIndex,这很容易. [SelectedIndex = 1;]< =做得好.

但是我想使用SelectedItem绑定此值.

我已经测试过了.

Maybe you know that ComboBox has SelectedItem.

This ComboBox have this itemsSource(1, 2, 3, 4).

And I want to set anything(1 or 2).

If I use SelectedIndex, it is easy. [SelectedIndex = 1;] <= well done.

But I want to Bind this value using SelectedItem.

I already test like this.

<ComboBox x:Name="cbOperatingType" ItemsSource="{Binding mUserGroupList}" SelectedItem="{Binding mDGSelectedItem.m_Operator_Type, Mode=TwoWay}" />



绑定ItemsSource做得很好.但是Binding SelectedItem无法运行.

运行程序时,ComboBox的TextBlock为空

mUserGroupList& mDGSelectedItem.m_Operator_Type也是属性(必须获取,设置)

请告诉我有关此问题的答案.
请为该问题提出解决方案.



Binding ItemsSource is well done. But Binding SelectedItem is not operating.

When Program is run, ComboBox''s TextBlock is empty

mUserGroupList & mDGSelectedItem.m_Operator_Type is also property(have get, set)

Please tell me answer for this problem.
Please suggest solution for this problem.

推荐答案

您必须将DisplayMemberPath设置为组合框.
现在应该可以了.

You have to set the DisplayMemberPath to the combobox.
Now it should work.

<ComboBox x:Name="cbOperatingType" ItemsSource="{Binding mUserGroupList}" DisplayMemberPath="{Binding Path=mDGSelectedItem.m_Operator_Type, Mode=TwoWay}" />


这篇关于如何在WPF .Net4.0中设置ComboBox的SelecteItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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