I have bound the Checked
event of a checkbox to a method. I am also passing two Command Parameters to that method through a converter (implementing IMultiValueConverter
). In the code below, the two CommandParameter
bindings are of type bool
and type string
respectively.
<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>
Why is it that if I replace the line:
<Binding ElementName="cbTopLeftHeader" Path="IsChecked"></Binding>
With:
<Binding RelativeSource="{RelativeSource Self}" Path="IsChecked"></Binding>
In my converter the IsChecked parameter changes from type bool
to type DependencyProperty
(DependencyProperty.UnsetValue
)?
How can I achieve passing the Checked
property without having the element bind to itself by name?
Get rid the interaction trigger and use the Command
and CommandParameter
properties of the CheckBox
:
<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>
Or stick with your current approach of binding to the CheckBox
using ElementName
. {RelativeSource Self}
of an InvokeCommandAction
is not a CheckBox
.