Does anyone know if and how one can disable items in a databound ListBox
based on the value of a property?
Preferably I would like a DataTrigger
which, when a certain property is false
, disables this item (make it impossible to select) without affecting other items in the ListBox
.
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Name="textBlock" Text="{Binding Description}"/>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsEnabled}" Value="False">
??
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
You can use ItemContainerStyle: