Tell me more ×  I have a listbox that contains a list of
persons. When the user clicks on an item the viewModel should
set the currentPerson object to the Object the user has clicked
on.  I have to use a ViewModel for this, so no code inside the
MainWindow.xaml.xs. Any Ideas how to solve this?  share|improve
this question add comment  1 Answer  up vote 3 down vote
accepted  That's very simple:  Add a property CurrentPerson to
your ViewModel and bind it to the SelectedItem property of the
ListBox.  Something like this:  View Model:  public Person
CurrentPerson     get { return _currentPerson; }
if(value == _currentPerson) return;         _currentPerson =
value;    <ListBox SelectedItem="{Binding CurrentPerson}" ...>
share|improve this answer +1: I usually bind to SelectedValue
though, i remember having issues with the SelecteItem property.
–  Baboon Oct 4 '12 at 13:21 @Baboon: That's not a good idea.
SelectedItem is the whole object. SelectedValue is the part of
the object defined by SelectedValuePath.