多个组合框的共享下拉列表(列表中的每个项目都可以单独使用) [英] Shared drop-down list for multiple ComboBoxes (each item in the list can be occupied singly)

查看:62
本文介绍了多个组合框的共享下拉列表(列表中的每个项目都可以单独使用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要重新创建一个共享的下拉列表选择,其中每个项目一次只能由一个控件选择.我能想到的最接近的例子是《将军》和《帝国时代》(多人游戏)等游戏中玩家的颜色选择.

I need to recreate a shared drop-down list selection where each item can be picked only by one control at a time. The closest example I can think of is player's color selection in games like Generals and Age of Empires (multiplayer).

例如,有一个列表:

{-无-",蓝色",红色",黄色"等}

{"- None -", "Blue", "Red", "Yellow", etc.}

有四个组合框.它们每个都以-无-"开头.如果ComboBoxA取"Blue",则其他ComboBox的列表中都不应包含"Blue".尽管ComboBoxA的列表中仍应带有蓝色".如果ComboBoxA选择了另一个选项,则所有其他ComboBox现在都应再次具有蓝色".与红色,黄色等相同.

There are four ComboBoxes. Each of them starts as "- None -". If ComboBoxA takes "Blue", no other ComboBox should have "Blue" in their list. Though ComboBoxA still should have "Blue" in its List. If ComboBoxA picks another option, all other ComboBoxes should now have "Blue" again. The same with Red, Yellow, etc.

关于如何实现这一目标的任何想法? MVVM是可取的,但不是必须的.

Any ideas on how to achieve this? MVVM is preferable but not a must.

推荐答案

基于我其他问题的答案,部分是Herman给出的答案以及许多自定义,我开始使用multiValue转换器.其转换方法如下:

Based on answers on my other question, partially the answer given by Herman and a lot of customization, I came to using a multiValue converter. Its convert method is as follows:

ObservableCollection<WorksheetColumn> worksheets = new ObservableCollection<WorksheetColumn>(values[0] as IEnumerable<WorksheetColumn>);
ComboBox combo = values[1] as ComboBox;
WorksheetColumn selected = combo.SelectedItem as WorksheetColumn;
int keepColumn = selected.ID;
return worksheets.Where(header => header.ID == 0 || header.Selected == false || header.ID == keepColumn);

这篇关于多个组合框的共享下拉列表(列表中的每个项目都可以单独使用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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