I'd be grateful if someone could give me some pointers on a very annoying problem I'm having - I'm going crazy trying to make this work as I'm sure there must be a simple solution but I can't see it!
As a result of the very helpful answers to my previous question posted on here, I'm attempting to use the MVVM approach in WPF.
I've got a listview in one page that binds to an ObservableCollection in the viewmodel & the listview's selected item is bound to a property called SelectedEntity in the viewmodel:
<Listview Name="listview" ItemsSource="{Binding Entities}" SelectedItem="{Binding SelectedEntity, Mode=TwoWay}">
In a different page I have a textbox bound to the Name property of SelectedEntity in the viewmodel:
<TextBlock Text="{Binding Path=SelectedEntity.Name}" />
The code in the viewmodel is:
Private Entity selectedEntity;
Public Entity SelectedEntity
{
get
{
return selectedEntity;
}
set
{
if (selectedEntity != value)
{
selectedEntity = value;
RaisePropertyChanged("SelectedEntity");
}
}
RaisePropertyChanged is a method that implements INotify开发者_JS百科PropertyChanged.
What I want to do is have the textblock update when the currently selected item in the listview changes but it just won't? Am I missing something really obvious?
Thanks very much for any guidance you can give me!
I got this working using the MVVM Light Toolkit and have uploaded it here
It works because the ViewModelLocator holds a static reference to the ViewModel
精彩评论