Disable particular item in the ListBox

谁说我不能喝 提交于 2019-12-12 05:48:05

问题


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:

  1. You can add the ListBoxItem by C# code and set the property properly.
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!