【问题标题】:Binding value as ConverterParameter绑定值作为 ConverterParameter
【发布时间】:2013-05-29 09:03:59
【问题描述】:

在我的资源字典中,我有以下风格:

 <Style TargetType="{x:Type propgrid:PropertyGridDataAccessorItem}" x:Key="{x:Type propgrid:PropertyGridDataAccessorItem}">
            <Style.Triggers>
                <Trigger Property="DataAccessorType" Value="Category">
                    <Setter Property="IsExpanded" Value="{Binding DisplayName, Converter={local:ExpandedCategoryConverter}}"/>
                </Trigger>
            </Style.Triggers>
  </Style>

我需要将一个值从我的 viewModel 绑定到 ConverterParameter,例如 ConverterParameter = {Binding MyProperty},但我们无法绑定到 ConverterParameter。

我该如何解决这个问题?

提前谢谢

【问题讨论】:

    标签: wpf xaml binding


    【解决方案1】:

    正如您所发现的,您无法绑定 ConverterParameter,因为它不是依赖属性。

    大多数情况下,解决方案是简单地使用MultiBindingmulti value converter,例如:

    <Trigger Property="DataAccessorType" Value="Category">
      <Setter Property="IsExpanded">
        <Setter.Value>
          <MultiBinding Converter="{local:ExpandedCategoryConverter}">
            <Binding Path="DisplayName"/>
            <Binding Path="WhatYouWantToPassInAsConverterParameter"/>
          </MultiBinding>
        </Setter.Value>
      </Setter>
    </Trigger>
    

    转换器当然需要适当更新。

    【讨论】:

    • 还有一个问题 - 当我设置绑定 时,我收到错误“期望一个属性值。属性值由单引号或双引号分隔”和“The在类型#Binding'中找不到属性''”。我该如何处理?
    • @Sasha: &lt;Binding Path="PropertyName" /&gt;.
    猜你喜欢
    • 2019-01-28
    • 2011-05-29
    • 2020-01-03
    • 2017-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-23
    相关资源
    最近更新 更多