【问题标题】:How to bind an indexer to a GridViewColumn in WPF?如何将索引器绑定到 WPF 中的 GridViewColumn?
【发布时间】:2011-03-02 19:04:35
【问题描述】:

在我的 ViewModel 对象中,我有一个这样的索引器:

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

但不确定如何在 Xaml 中绑定它。我试过这些:

<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}"/>

【问题讨论】:

    标签: c# .net wpf xaml data-binding


    【解决方案1】:

    试试这个:

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

    请注意,您的 indexer 属性必须提供一个 setter 才能使 TwoWay 绑定工作。

    【讨论】:

    • 感谢 Pavlo,它工作得很好。解决此问题后,我将添加二传手。顺便说一句,如果我有一个像 NewItems 这样的索引器属性,那么绑定会是 Binding NewItems[Blur],而不是 .
    猜你喜欢
    • 2011-02-08
    • 1970-01-01
    • 2016-09-23
    • 2017-09-14
    • 2021-12-21
    • 2016-05-06
    • 2016-05-09
    • 2018-05-22
    相关资源
    最近更新 更多