I have this model:
public class Option : BindableBase
{
private bool _enabled;
public bool Enabled
{
get
{
return _enabled;
}
set
{
SetProperty(ref _enabled, value);
}
}
private string _value;
public string Value
{
get
{
return _value;
}
set
{
SetProperty(ref _value, value);
}
}
}
In my viewmodel, I got a list Options
of type ObservableCollection<Option>
.
I use this XAML piece of code:
<ComboBox Width="200"
ItemsSource="{Binding Options}">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Value}"/>
<TextBlock Text="{Binding Enabled}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem">
<Setter Property="IsEnabled" Value="{Binding Enabled}"/>
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
I add some Option
in my list, some of them have the Enabled
property set to true
while others do not.
However, the ones having the property to false
are still enabled in the ComboBox
and I can select them (while I should not!). When using this line of code:
<Setter Property="IsEnabled" Value="false"/>
The options are effectively disabled (I can't select any of them) but I'd like to use some binding. Can someone explain what I'm doing wrong here?