Skip to content

How to update views when underlying model changes #17762

Answered by reelthymeos
reelthymeos asked this question in Q&A
Discussion options

You must be logged in to vote

The following worked for me, if anyone is interested.

I used inversion of control to accomplish the task. Each sub-viewModel is passed an instance of the MainViewModel in its constructor. So in the MainViewModel constructor we have the following

public MainViewModel()
	{
	
		MyViewModelA = new ViewModelA(this);
		MyViewModelB = new ViewModelB(this);
	}

Then, inside each subviewmodel, we subscribe to the 'propertyChanged' event in the MainViewModel (in this case the event is that the Model changed). MainViewModel is a ReactiveObject.


public ViewModelA(MainViewModel mainViewModel)
		{
			// Subscribe to the ActiveModel change from MainViewModel
			mainViewModel.PropertyChanged += (sender,…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@reelthymeos
Comment options

@LaurentInSeattle
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by reelthymeos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants