Disallow/Block selection of disabled combobox item in wpf

You can achieve this by setting IsEnabled property of a ComboBoxItem to false;

So each item in ComboBox’s ItemSource (i.e. Cars in your case) can be an object having some property (say IsSelectable) specifying whether it should be enabled or disabled and then use it with a style to make an item un-selectable. something like this –

<Style TargetType="ComboBoxItem"> 
   <Setter Property="IsEnabled" Value="{Binding IsSelectable}"/> 
</Style> 

Update:

<Grid>
    <ComboBox
        Width="120"
        Margin="87.2,44.8,0,0"
        HorizontalAlignment="Left"
        VerticalAlignment="Top"
        ItemTemplateSelector="{StaticResource QualityComboBoxTemplateSelector}"
        ItemsPanel="{DynamicResource ItemsPanelTemplateHorizontal}"
        ItemsSource="{Binding Cars}"
        SelectedItem="{Binding SelectedItm}">
        <ComboBox.ItemContainerStyle>
            <Style TargetType="ComboBoxItem">
                <Setter
                    Property="IsEnabled"
                    Value="{Binding IsSelectable}" />
            </Style>
        </ComboBox.ItemContainerStyle>
    </ComboBox>
</Grid>

Leave a Comment