Home > DeveloperSection > Forums > Resetting binding's source in wpf
john rob

Total Post:108

Posted on    August-19-2014 3:19 AM


 1 Reply(s)
 1111  View(s)
Rate this:

I have this list box:

<ListBox DockPanel.Dock="Left" HorizontalAlignment="Left" Width="150"

                 ItemsSource="{Binding PcConfigurations, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}">



                    <TextBlock Text="{Binding}">


                            <i:EventTrigger EventName="MouseDoubleClick">

                                <cmd:EventToCommand Command="{Binding LocalConfigurationCommand}"








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

Total Post:411

Posted on    August-19-2014 3:37 AM

The 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}}"


Don't want to miss updates? Please click the below button!

Follow MindStick