如何将组合框中的项目设置为选定状态
似乎没有人找到一种方法来将组合框项目设置为使用 SelectedItem="Binding Property" 进行选择。
解决方案是在组合框项源中的 ViewModel 对象中使用 IsSelected 属性吗?
It seems nobody has yet found a way to set the comboboxitem as selected with a SelectedItem="Binding Property".
Is the solution to use a IsSelected Property in the ViewModel object within the combobox itemssource?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我们绑定组合框的成功方法如下......
Our successful approach for binding a combobox is the following...
不知道为什么在没有看到代码的情况下无法将数据绑定到 ComboBox 上的 SelectedItem。下面向您展示了如何使用 CollectionView 来执行此操作,CollectionView 内置了组合框支持的当前项目管理。 CollectionView 有一个 CurrentItem get 属性,您可以使用它来获取当前选定的内容。
XAML:
隐藏代码:
Not sure why you can't data bind to SelectedItem on a ComboBox without seeing your code. Below shows you how to do it using a CollectionView which has current item management built in which comboboxes supports. CollectionView has a CurrentItem get property you can use to get currently selected.
XAML:
Code behind:
我发现在组合框源代码中,selectitem是通过使用列表selectedindex设置的
使用此方法的组合框
每次通过代码设置
Selecteditem
时, 始终返回-1
或null
x = itemsCollection.IndexOf(value);
它被报告为组合框代码中的错误(82115)
,因此工作方法是直接使用
SelectedIndex
并绑定到它而不是SelectemItem
属性,如果您愿意,您可以只读取item 绑定到SelectedItem
属性,或者使用ItemsSource
本身在代码中获取它。这对我来说很好。
what i found is that in combobox soure code, selecteditem is set by using list selectedindex
combobox using
this method always return
-1
ornull
every time you setSelecteditem
by codex = itemsCollection.IndexOf(value);
its reported as bug (82115) in combobox code
so the working method is to use
SelectedIndex
directly and bind to it instead ofSelectemItem
property and if you want you can read only the item from binding to theSelectedItem
property or obtain it in your code usingItemsSource
itself.This working for me fine.