如何设置数据触发器来选择/取消选择列表框项目?
这个问题困扰了我一段时间,一直搞不明白。我有多个列表框,每个列表框绑定到不同的列表。最后,我只是希望能够保留它,以便在所有列表中一次只选择一项。有什么想法吗?
这一定很简单,但我没有运气。我尝试了使用 gloabl\static DependencyObject 来匹配每个 ListBoxItem 的 Tag 属性的想法,但在更新值时无法为每个列表框触发数据触发器。
例如,如果我的表单有不同的列表框,每个列表框都有自己的支持列表集合和自己的数据模板,我希望能够从一个列表中选择一个项目,并使其成为唯一选定的项目。这意味着我希望其他人取消选择。我尝试将 ListBoxItem IsSelected 属性绑定到 MultiBinding,该 MultiBinding 将唯一的 ListBoxItem 值与全局值进行比较,但没有运气。
据我了解,IsSynchronizedWithCurrentItem 适用于使用相同支持集合的列表。
This issue has been plaguing me for a while, and I just can't get it right. I have multiple listboxes each bound to different lists. In the end, I just want to be able to keep it so only one item is selected at a time across all the lists. Any ideas?
This has got to be very simple, but I have had no luck. I tried the idea of a gloabl\static DependencyObject to match against each ListBoxItem's Tag property, but have trouble getting the datatrigger to fire for each listbox when the value is updated.
For example, if my form has different ListBoxes, each with their own backing list collections and their own DataTemplates, I want to be able to select an item from one list, and have it be the only selected item. Which means I want the others to unselect. I tried binding the ListBoxItem IsSelected Property to a MultiBinding that compares the unique ListBoxItem value to a global value, but had no luck there.
As far as I understand, IsSynchronizedWithCurrentItem works for lists using the same backing collection.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,这里尝试一下:
获取每个列表的 collectionviewsource.View (如果您还没有使用这些,获取默认视图)。在视图中,您可以订阅 CurrentChanged 和其中彼此列出了 CollectionViewSource.View。MoveCurrentToPosition< /a>(-1);
ok, here's a try:
get the collectionviewsource.View of each of your lists (if you don't use these already, get the default views). In the View you can subscribe to CurrentChanged and in there for each other lists' CollectionViewSource.View.MoveCurrentToPosition(-1);