tags:

views:

29

answers:

3

i have three listboxes, whose itemsSource is binded to a list, list and dictionary. i want to add the selected user and selected book to the dictionary with a command but i can't take the selected items. i am trying to obey the mvvm. i have a booklist and a userlist in my viewmodel which are binded to the given listboxes in my view. i couldn't send the selected items to my viewmodel. how can i do this? thanks for helping in advance.

+1  A: 

Just bind a property to SelectedItem:

<ListBox 
  ItemsSource="{Binding Books}" 
  SelectedItem="{Binding SelectedBook}"/>

And in the ViewModel

public class Library : INotifyPropertyChanged
{
  public ObservableCollection<Book> Books {get;private set;}
  public Book SelectedBook {get;set;}
}
Will
thank you so much it really helped...
cemregoksu
+1  A: 

In your viewModel, couldn't you create a SelectedBook and a SelectedUser and bind those to the SelectedItem of your ListBoxes? Then, when they change, add them to your dictionary.

JSprang
thank you for your help, it was the right point.
cemregoksu
+1  A: 

You can also use standard binding syntax using a slash (/).

{Binding Books/}

will allow you to bind directly to the current item in a collection.

Mark Green