I have a number of items in a listview, some of which may be in a readonly state. When in readonly state, the items are disabled. However, I need the user to be able to remove them by clicking a button which is displayed using a celltemplate on a gridviewcolumn. By default this is disabled by default and setting IsEnabled="true" on the item itself does not enable it regardless of the state of the container.
I'd also like the user to be able to select the item to remove it in a multiselect mode. However selection is also disabled by default. What is the best way to achieve both ways of removing the item?
The item is disabled inside a user control using the following:
ListBoxItem listBoxItem = (Item is int) ? GetListBoxItemFromIndex((int)Item) : GetListBoxItemFromItem(Item);
if (listBoxItem != null)
{
listBoxItem.IsEnabled = Enable;
}
The button is defined in XAML as follows. It is a part of a gridviewcolumn inside a listview using a gridview to display the rows:
ImageSource="/App;component/Images/Red_Delete16.png"
ToolTip="Removes the train service from the list."
Name="buttonRemoveTrainService"
Visibility="{Binding IsRemovable, Converter={StaticResource booleanToVisibilityConverter}}">
....
Any clues would be much appreciated!

Mark18 reputationPosted Sep 21, 2010, 7:26 AM EDT
I added the following trigger to each text based GridViewColumn to 'gray' out the text if the item is readonly:
Sam HobbsRank #108 · 20.5K reputationPosted Sep 21, 2010, 6:07 PM EDT
Mark18 reputationPosted Sep 22, 2010, 2:07 AM EDT
In WPF listview is actually just a specialization of listbox so therefore it is valid to cast a listview back to a listbox and a listviewitem back to listboxitem. See the following for more information:
http://stackoverflow.com/questions/227231/wpf-listbox-vs-listview-how-to-choose-for-data-binding