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
2010-08-06 12:19:17
thank you so much it really helped...
cemregoksu
2010-08-06 12:59:51
+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
2010-08-06 12:20:57
+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
2010-08-06 14:43:19