Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to enable/disable comboBox items for different comboBoxes in wpf by click on one item using MVVM pattern and 1 ObservableCollection for comboBoxes?

$
0
0

Hello. I create a project using MVVM pattern. I create a wpf form with comboBoxes. In ViewModel I create ObservableCollection for ItemsSource for comboBoxes with string values:

public ObservableCollection<string> ComboBoxItems
    {
        get; set;
    }
 

Also in ViewModel constructor I create list of Models (for each comboBox). My Model class have only two properties: SelectedItem and IsEnabledItem.

I want to have a logic like if I select one item in one comboBox it shoud be disable in this comboBox and in all others. How could I do this with Binding? Now my xaml code look like this, but it disabled only selected comboBox item and only in one comboBox, where he was called from:

<ComboBox  ItemsSource="{Binding ComboBoxItems}"
           SelectedItem="{Binding SelectedItem }" IsEditable="True"><ComboBox.ItemContainerStyle><Style TargetType="ComboBoxItem"><Setter Property="IsEnabled" Value="{Binding IsEnabledItem}" /></Style></ComboBox.ItemContainerStyle></ComboBox>


Thanks for your help.





Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>