WPF MultiBinding Converter对象类型
问题描述:
我已经将复选框的Checked
事件绑定到方法。我还通过一个转换器将两个Command参数传递给该方法(实现IMultiValueConverter
)。在下面的代码中,两个CommandParameter
绑定的类型分别为bool
和string
。WPF 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参数变化键入DependencyProperty
(DependencyProperty.UnsetValue
)?
我怎样才能达到通过Checked
属性没有通过名称绑定到自己的元素?
答
摆脱互动触发,并使用CheckBox
的Command
和CommandParameter
属性:
<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
您没有绑定CheckBox的CommandParamter属性(例如[this](https://*.com/q/7617375/1136211)),因此'RelativeSource Self'不是CheckBox。 – Clemens