简体   繁体   中英

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.

Try this:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM