从 ViewModel 绑定 WPF ComboBox 的数据 - 无法更改所选项目
我会立即解决这个问题...我的基本视图模型类正在实现 INotifyPropertyChanged。场景如下:
我有一个带有单个视图模型的视图。该视图是一个主视图/细节视图,其中主视图是一个 Game
对象的列表框,我可以毫无问题地填充这些对象。当在主列表框中选择 Game
对象时,我想在各种控件中填充一些详细信息。给我带来问题的控件是组合框。
现在,使用 Team
对象集合填充组合框
。每个 Game
对象都有一个“Team”对象,填充 combobox
后,我想在 中选择适当的
。Team
对象Game
对象指定的组合框
现在,我知道这在某种程度上是有效的,因为如果我对 textbox
进行相同的绑定,就会出现正确的信息(我可以让绑定的 Team
对象出现在文本框
,但我无法从列表中选择它)。
我严重迷失了,已经为此工作了几个小时。有人可以帮忙吗?
编辑:我有一种感觉这与对象引用有关。但是 SelectedValue
仍然有效吗?
I'll get this out of the way right off the bat... my base view model class is implementing INotifyPropertyChanged
. Here's the scenario:
I have a single view with a single view model. The view is a master/detail with the master being a list box of Game
objects that I'm populating without issue. When a Game
object is selected in the master list box, I want to populate some details in various controls. The control that's causing me problems is a combo box.
Now, the combobox
is being populated using a collection of Team
objects. Each Game
object has a "Team" object and once the combobox
is populated, I want to select the appropriate Team
object in the combobox
that the Game
object specifies.
Now, I know this is working to some degree because if I do the same binding to a textbox
, the right information appears (I can get the bound Team
object to appear in the textbox
, but I can't get it to select from the list).
I'm seriously lost, been working on this for a few hours now. Can anyone assist?
Edit: I have a feeling this has something to do with the object references. But wouldn't SelectedValue
still work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ViewModel:
团队类别:
视图:
ViewModel:
Team Class:
View: