Among client applications, this problem is the most common among Single Page applications. Experienced developers often split a View into several Views as sub-Views. These jobs require a lot of practical knowledge.
Creating Inheritance Relationship for ViewModel
Now let’s see how we access the data in the parent ViewModel in WPF:
When we look at the usage above, a FindAncestor method is used to get data from a parent object according to the object specified with AncestorType. Starting from here, we are preparing an extension method for our ViewModel.
Thanks to this method, we can get the data of the object in the upperclass with the following usage.
Our app has now become more intuitive. According to the inheritance chain, ParentViewModel’s data can be easily accessed with SubViewModel.