Joan Venge
Joan Venge

Reputation: 330962

How to bind an indexer to a GridViewColumn in WPF?

In my ViewModel object I have a this indexer like:

public bool this[enum effectType]
{
    get { return CheckList.First ( e => e.EffectType == effectType ).IsChecked; }
}

but not sure how to bind this in Xaml. I have tried these:

<GridViewColumn
    <GridViewColumn.CellTemplate>
        <DataTemplate>
            <CheckBox
                IsChecked="{Binding Item[Blur], Mode=TwoWay}"/>
        </DataTemplate>
    </GridViewColumn.CellTemplate>
</GridViewColumn>

IsChecked="{Binding this[Blur], Mode=TwoWay}"/>

IsChecked="{Binding AllEffects[Blur], Mode=TwoWay}"/>

AllEffects is an ObservableCollection already binded to the ListBox itself and the columns are already populated except the checked ones which I am trying to bind to this indexer.

Upvotes: 1

Views: 1113

Answers (1)

Pavlo Glazkov
Pavlo Glazkov

Reputation: 20746

Try this:

<CheckBox IsChecked="{Binding .[Blur], Mode=TwoWay}"/>

Please note that your indexer property must provide a setter in order TwoWay binding to work.

Upvotes: 3

Related Questions