Mark

Mark

  • NA
  • 19
  • 0

Enabling individual items inside a disabled listviewitem

Sep 21 2010 5:50 AM
I'm struggling with the following and would appreciate some help:

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:

<GridViewColumn Header="Shortcuts" Width="75" >
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition/>
                                    <ColumnDefinition/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <App:IconButton Margin="1,1,1,1" Width="16" Height="16" Grid.Column="0"
                                                                            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!

Answers (3)