简体   繁体   English

多个组合框绑定到同一个源,并且对项目有条件的可见性

[英]Multiple combo boxes bound to same source with conditional visibility on items

Unlike many questions related to this, I'm not having an issue with all combo box values being changed at when changing one combo box selection. 与与此相关的许多问题不同,在更改一个组合框选择时,所有组合框值都不会发生变化。

My problem is that I want to change the visibility of certain items when they are selected in the other list. 我的问题是,当某些项目在其他列表中选择时,我想更改它们的可见性。 I have two input port combo boxes and when I select port 5, say, on the first one, I want port 5 to not appear in the drop down for the second combo box. 我有两个输入端口组合框,当我选择端口5时,例如,在第一个组合框上,我希望端口5不出现在第二个组合框的下拉菜单中。

I've tried this solution How to set combox item visibility? 我已经尝试过此解决方案如何设置combox项目可见性? as it looked very promising but it won't let me cast from string to ComboBoxItem in the code-behind. 因为它看起来非常有前景,但是它不能让我在后面的代码中将stringstringComboBoxItem

What else am I to do? 我还要做什么? I thought of creating a style in the XAML itself, but I can't quite figure out the conditions to use within the XAML and can't seem to find any topics over it. 我曾考虑在XAML本身中创建一种样式,但是我无法完全弄清楚在XAML中使用的条件,并且似乎无法在其上找到任何主题。 Lastly, I also have conditions in the setters for my input properties to check that the value the port is being set to is not the same as the other port, but it's not seeming to do anything for the view. 最后,我在设置程序中还具有一些条件,可用于输入属性,以检查端口设置为与其他端口不同的值,但似乎对视图没有任何作用。

Are you using an ObservableCollection? 您是否正在使用ObservableCollection? This would allow for two way data binding whereas your UI will reflect the contents of each ObservableCollection in realtime if added to or removed from in an event. 这将允许两种方式的数据绑定,而如果在事件中添加或删除了事件,则UI将实时反映每个ObservableCollection的内容。 In another scenario, I had to apply a custom object to bind to in order to determine whether or not to show it, however, it was not the contents of a combobox, which are harder to access. 在另一种情况下,我必须应用一个自定义对象进行绑定才能确定是否显示它,但是,并不是组合框的内容很难访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM