WPF MultiBinding Converter对象类型

问题描述:

我已经将复选框的Checked事件绑定到方法。我还通过一个转换器将两个Command参数传递给该方法(实现IMultiValueConverter)。在下面的代码中,两个CommandParameter绑定的类型分别为boolstringWPF MultiBinding Converter对象类型

<CheckBox Name="cbTopLeftHeader" Content="Top Left Header"> 
     <i:Interaction.Triggers> 
      <i:EventTrigger EventName="Checked"> 
       <i:InvokeCommandAction Command="{Binding IncludeCheckedCommand}"> 
        <i:InvokeCommandAction.CommandParameter> 
         <MultiBinding Converter="{StaticResource MultiBindingConverter}" ConverterParameter="IncludeChecked"> 
          <Binding ElementName="cbTopLeftHeader" Path="IsChecked"></Binding> 
          <Binding Source="{StaticResource TopLeft}"></Binding> 
         </MultiBinding> 
        </i:InvokeCommandAction.CommandParameter> 
       </i:InvokeCommandAction> 
      </i:EventTrigger> 
     </i:Interaction.Triggers> 
</CheckBox> 

为什么,如果我更换行:

<Binding ElementName="cbTopLeftHeader" Path="IsChecked"></Binding> 

有了:

<Binding RelativeSource="{RelativeSource Self}" Path="IsChecked"></Binding> 

在我的转换器从bool型器isChecked参数变化键入DependencyPropertyDependencyProperty.UnsetValue)?

我怎样才能达到通过Checked属性没有通过名称绑定到自己的元素?

+1

您没有绑定CheckBox的CommandParamter属性(例如[this](https://*.com/q/7617375/1136211)),因此'RelativeSource Self'不是CheckBox。 – Clemens

摆脱互动触发,并使用CheckBoxCommandCommandParameter属性:

<CheckBox Name="cbTopLeftHeader" Content="Top Left Header" Command="{Binding IncludeCheckedCommand}"> 
    <CheckBox.CommandParameter> 
     <MultiBinding Converter="{StaticResource MultiBindingConverter}" ConverterParameter="IncludeChecked"> 
      <Binding RelativeSource="{RelativeSource Self}" Path="IsChecked"/> 
      <Binding Source="{StaticResource TopLeft}"></Binding> 
     </MultiBinding> 
    </CheckBox.CommandParameter> 
</CheckBox> 

或与您当前使用ElementName结合CheckBox办法坚持下去。 InvokeCommandAction{RelativeSource Self}不是CheckBox

+0

谢谢你mm8。我没有意识到(虽然现在看起来很明显)默认情况下复选框的命令是'Checked'事件。您的回答和Clemens评论上面回答我的问题。 – Doug