【问题标题】:wpf - templates - pass template item as ConverterParameterwpf - 模板 - 将模板项作为 ConverterParameter 传递
【发布时间】:2010-12-25 11:58:51
【问题描述】:

我有一个 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>

【问题讨论】:

    标签: wpf data-binding resources binding


    【解决方案1】:

    使用多重绑定代替你的绑定,那么你可以绑定多个参数。

    ms doco 关于多重绑定

    【讨论】:

    • 这很有趣,在记住多重绑定之前,我已经做了几次(尝试绑定转换器参数):)
    猜你喜欢
    • 2011-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-23
    相关资源
    最近更新 更多