[This post is part of the developer's manual preview published on this blog. You can find temporary TOC here.]
One of the main advantages of the hierarchical View composition is the fact that we can access the members of other Views from a given View. So, as we have seen in the previous article, we can access the members of the host (parent) View by simply calling this.Host property on the current View.
Accessing other Views, however, has several limitations which one should bear in mind.
Before we start to describe these limitations, let us consider the process of how Views are loaded and what is the current View. Namely, every time you access a particular route, you are loading all the Views in that hierarchy, ending with the last one. The current View is always the last View loaded. Let us take a look at the following diagram to understand this mechanism.
- Only Views in the current route can be accessed
- Only parent Views can be accessed (parent cannot access child View)
In the image above, we see two different routes. If you are accessing the orange route (ControlPanel.ProductsView.ProductNewView), first the ControlPanel View will be loaded, then the ProductsView View will be loaded and finally the ProductNewView View will be loaded. The last loaded View is always the current View, and on the screen the user interface of that View will be displayed.
Only Views in the current route can be accessed
Since, only the Views of the current route are loaded, it follows that only them we can access. Namely, if we take again look at the diagram of the Views and routes, if the blue route is being accessed, we cannot access ProductsTagsView and its members for example, because that View has not been loaded.
Only Parent Views can be accessed
Second rule of the View access it that we can only access the parent Views, through the Host property. Namely, since the Views are being loaded dynamically, the View does not know about its children, until the whole hierarchy is loaded. As it was described in the previous article, we access the parent Views and their members through the Host property.
There are certain workarounds for these limitations, but with proper design of the hierarchy, these limitations never present a problem. In the overview of the ViewModeControl class, which comes at the end of this series, we will examine various properties that will give us sufficient information about Views on either side of the hierarchy.