Reputation: 1077
class ChildViewModel : ParentViewModel
class ParentViewModel has -> public string PropertyA; public string PropertyB;
I have 2 screentab workflows, one for the parent and the other for the child (obviously dependent on parent data). I want to bind a PropertyA to a textblock in the childView, such that whenver I change the screentab to the parentView and modify PropertyA, it should reflect in the childView automatically.
I have defined a property in the childViewModel (sortof pseudo):
public string PropA
get { return PropertyA; }
set
{
PropertyA = value;
OnPropertyChanged("PropertyA");
}
I have also tried UpdateSourceTrigger, Mode=twoway properties in view - WPF.
Still cannot get the Property to change.
Any suggestions welcome....
Upvotes: 0
Views: 176
Reputation: 4636
If ChildViewModel inherits from ParentViewModel as you've shown then why would you have a second property PropA? Why not just bind the ChildView to ParentViewModel.PropertyA?
I'm assuming this is not actual inheritance but you are wanting to forward the ParentViewModel events to the ChildViewModel. To do this you need to listen to the ParentViewModel's PropertyChanged events... you could do this by...
// listen to parentViewModel PropertyChanged events
parentViewModel.PropertyChanged += HandleParentPropertyChangedEvents;
Just be sure you remove your event handler if you close or change the ChildViewModel.
In ChildViewModel your handler will look like this...
private void HandleParentPropertyChangedEvents(object sender, PropertyChangedEventArgs e)
{
OnPropertyChanged(e.PropertyName);
}
This will re-fire any PropertyChanged events from the parent on the child. In your ChildViewModel event handler you could also filter the properties you are forwarding if you wanted to.
Upvotes: 1