I have this list box:
<ListBox DockPanel.Dock="Left" HorizontalAlignment="Left" Width="150"
ItemsSource="{Binding PcConfigurations, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<cmd:EventToCommand Command="{Binding LocalConfigurationCommand}"
CommandParameter="{Binding}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
When I run the application I got this error in the output:
System.Windows.Data Error: 40 : BindingExpression path error: 'LocalConfigurationCommand' property not found on 'object' ''PcConfiguration_0CC914504C64AE357F440BEA28C5F73FD3627331B5E407B6D7DD75076453D393' (HashCode=20396001)'. BindingExpression:Path=LocalConfigurationCommand; DataItem='PcConfiguration_0CC914504C64AE357F440BEA28C5F73FD3627331B5E407B6D7DD75076453D393' (HashCode=20396001); target element is 'EventToCommand' (HashCode=27147755); target property is 'Command' (type 'ICommand')
I guess it is because the current path that the
EventToCommand Command="{Binding LocalConfigurationCommand}"....
is looking for is set to the 'location' of what the listbox has set in its binding.
So I'd like to ask how can I put there location of my ViewModel, so it can find that command, but the location in CommandParameter={Binding} will still be current item from ListBox.
Pravesh Singh
19-Aug-2014The viewmodel is in fact the ListBox's data context, and you can get to the ListBox by using RelativeSource:
<cmd:EventToCommand Command="{Binding Path=DataContext.LocalConfigurationCommand, RelativeSource={RelativeSource AncestorType=ListBox}}"
CommandParameter="{Binding}"/>