wpf - templates - 将模板项作为ConverterParameter传递

时间:2009-12-11 00:31:36

标签: wpf data-binding resources binding

我有一个ListBox模板。在ListBox中,我在ListBoxItems上有一个模板。我想禁用其中的一些项目(我仍然在研究我想用来使“事件”发生的事情,所以我现在刚刚放入IsSelected)

我的问题是我需要获取ListBoxItem的一些数据才能知道它是否应该被禁用(即,我们现在正在查看哪一个......)

我以为我会使用ConverterProperty,但它似乎只允许资源和硬编码值(我不能用反射进行数据绑定,我不想这样做。)

我尝试传入RelativeSource Self和ConverterParameter,并且只传入了一个不会强制转换为ListBoxItem的RelativeSource类型的对象。

有什么想法吗?

<Style x:Key="CheckBoxListStyle" TargetType="ListBox">
    <Style.Resources>
        <Style TargetType="ListBoxItem">
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsSelected, 
                    RelativeSource={RelativeSource Self}, 
                    Converter={StaticResource DisableWorkItemConverter}, 
                    ConverterParameter={RelativeSource Self}}" Value="True">

                    <Setter Property="IsEnabled" Value="False"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Style.Resources>
</Style>

1 个答案:

答案 0 :(得分:3)

使用多重绑定代替您的绑定,然后您可以绑定到多个参数。

关于多重绑定的

ms doco

相关问题