Good question, I thought about this, and I will probably approach it with MultiBinding and the corresponding ValueConverter, i.e.
<StackPanel> <StackPanel.Resources> <local:ComboBoxItemsSourceFilter x:Key="ComboBoxItemsSourceFilter"/> </StackPanel.Resources> <ComboBox Name="cb1"> <ComboBox.ItemsSource> <MultiBinding Converter="{StaticResource ComboBoxItemsSourceFilter}"> <Binding Path="Emps"/> <Binding ElementName="cb2" Path="SelectedItem"/> <Binding ElementName="cb3" Path="SelectedItem"/> </MultiBinding> </ComboBox.ItemsSource> </ComboBox> <ComboBox Name="cb2"> <ComboBox.ItemsSource> <MultiBinding Converter="{StaticResource ComboBoxItemsSourceFilter}"> <Binding Path="Emps"/> <Binding ElementName="cb1" Path="SelectedItem"/> <Binding ElementName="cb3" Path="SelectedItem"/> </MultiBinding> </ComboBox.ItemsSource> </ComboBox> <ComboBox Name="cb3"> <ComboBox.ItemsSource> <MultiBinding Converter="{StaticResource ComboBoxItemsSourceFilter}"> <Binding Path="Emps"/> <Binding ElementName="cb1" Path="SelectedItem"/> <Binding ElementName="cb2" Path="SelectedItem"/> </MultiBinding> </ComboBox.ItemsSource> </ComboBox> </StackPanel>
public class ComboBoxItemsSourceFilter : IMultiValueConverter { #region IMultiValueConverter Members public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { var collection = new List<object>((object[])values[0]); foreach (var item in values.Skip(1)) { if (item != null) collection.Remove(item); } return collection; } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { throw new NotSupportedException(); } #endregion }
Since you are doing this in code after adding all of these bindings, this should not be a big problem, just drag and drop all the lists into a list and you can iterate over them. The converter may need some tuning, since it is assumed that the input collection ( values[0] ) can be translated to object[] .
This way of doing this sadly raises many exceptions with a first chance, the reason of which I could not determine until now ...
The first random error like "System.Runtime.InteropServices.COMException" occurred in UIAutomationProvider.dll
source share