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!
3 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
MarkPosted Sep 22, 2010, 6:07 AM
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
Sam HobbsPosted Sep 21, 2010, 10:07 PM
MarkPosted Sep 21, 2010, 11:26 AM
IsEnabled="{Binding IsReadOnly, Converter={StaticResource inverseBooleanConverter}}"I added the following trigger to each text based GridViewColumn to 'gray' out the text if the item is readonly: