问题
I bind list of objects to my ListBox in WindowsPhone application. This business object has one boolean property. Based on the Boolean property i need to set the IsEnabled property in the ListBoxItem.
Is there any way to achieve this in WindowsPhone ListBox ?
回答1:
There're few ways to achieve this:
- You can add the ListBoxItem by C# code and set the property properly.
- In Xaml, inside the list box, place the following:
<ListBox.Resources>
<Style TargetType="ListBoxItem">
<Setter Property="IsEnabled" Value="{Binding Content.IsEnabled, RelativeSource={RelativeSource Self}}"/>
</Style>
</ListBox.Resources>
Here I assume that the property name in your model object is IsEnabled, change it according to its real name.
来源:https://stackoverflow.com/questions/11520879/disable-particular-item-in-the-listbox