I have a TreeView
setup with a HierarchialDataTemplate
. It's ItemsSource
is bound to a collection of Overlay
objects in my viewmodel, where each Overlay
has a collection of Layer
objects (thus the HierarchialDataTemplate
). For each Overlay
, I'm displaying a CheckBox
and a Label
which is simply bound to the Overlay
's Name
property.
What I'm trying to do is, each time one of the checkboxes is checked/unchecked, the current Overlay
and the IsChecked
property of the CheckBox
will be sent as command parameters to my viewmodel.
If I'm not using the MultiValueConverter
, I can send one of the properties fine. But I need to send both as parameters.
Below is the related .xaml for the treeview. I'm only showing the necessary parts and just the Checked
trigger because the Unchecked
is exactly the same:
<TreeView ItemsSource="{Binding OverlaysViewSource}" Name="LayersTreeView">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Layers}" >
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="True">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding DataContext.SetVisibilityCmd, RelativeSource={RelativeSource AncestorType=UserControl}}" >
<i:InvokeCommandAction.CommandParameter>
<MultiBinding Converter="{StaticResource multiValueConverter}">
<Binding Path="IsChecked, RelativeSource={RelativeSource AncestorType=CheckBox}" />
<Binding/>
</MultiBinding>
</i:InvokeCommandAction.CommandParameter>
</i:InvokeCommandAction>
</i:EventTrigger>
</i:Interaction.Triggers>
</CheckBox>
<Label Content="{Binding Name}" />
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
So in the MultiBinding
, the first one: <Binding Path="IsChecked, RelativeSource={RelativeSource AncestorType=CheckBox}" />
to try and send the checkbox's IsChecked
property. However, the value I'm getting in the command is DependencyProperty.UnsetValue
.
The second one is just for the current Overlay
item, but the whole TreeView
is being sent as a parameter.
Update:
The Overlay
class is a third party control and is used in a lot of places that I can't modify. So I can't just add a property to it.
Update2: I've managed to get the Overlay
to send properly. Just need the IsChecked
property now.
The binding for IsChecked
should use {RelativeSource Self}
, since the binding is being applied to the CheckBox
via the Style
.
Your update to your question shows you've already solved the other one.