There's this combo box in a WPF application that is populated from an enum. How would one disable some of its items? Disabling has to be dynamic, based on another property in the ViewModel.
<ComboBox ItemsSource="{utility:EnumMarkupExtension {x:Type types:SomeEnum}}"
SelectedItem="{Binding Path=MySelection, Converter={StaticResource SomeEnumToString}}" />
EnumMarkupExtension
is defined thus:
public sealed class EnumMarkupExtension : MarkupExtension
{
public Type Type { get; set; }
public EnumMarkupExtension(Type type) => this.Type = type;
public override object ProvideValue(IServiceProvider serviceProvider)
{
string[] names = Enum.GetNames(Type);
string[] values = new string[names.Length];
for (int i = 0; i < names.Length; i++)
values[i] = Resources.ResourceManager.GetString(names[i]);
return values;
}
}
(SomeEnumToString
is an IValueConverter
which probably is not relevant to this)
Is there some obvious method of doing this that I'm missing?
I've seen solutions like this
https://www.codeproject.com/Tips/687055/Disabling-ComboboxItem-in-ComboBox-Control-using-C
but can't figure out how to pass a property to IValueConverter
since ConverterParameter
is not bindable.