Here is a solution for you:
Windows Disable ComboBoxItem in WPF ComboBox Control using Converter sample in C# for Visual Studio 2010[
^]
UPDATE: I normally only do MVVM, so here is an adaption that will enable you to selectively disable individual items. All that you need to do is style the items.
1. Notification base so that code-behind changed to item enabled state will be reflected in the UI:
public abstract class ObservableBase : INotifyPropertyChanged
{
public void Set<TValue>(ref TValue field, TValue newValue,
[CallerMemberName] string propertyName = "")
{
if (EqualityComparer<TValue>.Default
.Equals(field, default(TValue))
|| !field.Equals(newValue))
{
field = newValue;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
2. Next we need a class to hold the value of the ComboBoxItem and the IsEnabled state:
public class Widget : ObservableBase
{
private bool isEnabled = true;
public bool IsEnabled
{
get => isEnabled;
set => Set(ref isEnabled, value);
}
private string text;
public string Text
{
get => text;
set => Set(ref text, value);
}
}
3. Now wire up the code-behind:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
InitData();
DataContext = this;
}
private void InitData()
{
Items = new ObservableCollection<Widget>
{
new Widget{ Text="Widget1" },
new Widget{ Text="Widget2", IsEnabled = false },
new Widget{ Text="Widget3", IsEnabled = false },
new Widget{ Text="Widget4", IsEnabled = false },
new Widget{ Text="Widget5" }
};
}
public ObservableCollection<Widget> Items { get; set; }
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Debugger.Break();
}
}
4. Now we can do the UI:
<Window.Resources>
<Style x:Key="ComboBoxItemStyle1" TargetType="{x:Type ComboBoxItem}">
<Setter Property="IsEnabled" Value="{Binding IsEnabled, FallbackValue=true}"/>
</Style>
</Window.Resources>
<Grid>
<ComboBox ItemsSource="{Binding Items}"
DisplayMemberPath="Text"
ItemContainerStyle="{DynamicResource ComboBoxItemStyle1}"
SelectionChanged="ComboBox_SelectionChanged"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Width="200"/>
</Grid>