My main view model (mainViewModel
) contains an inner view model (innerViewModel
) that is bound to it's view (innerView) using a DataTemplate.
In my mainView
I have a ContentPresenter
that has it's Content property bound to the innerViewModel
and it's Visibility bound to an IsVisible
property. The Visibility property is Collapsed and will very rarely be set to Visible.
My mainViewModel
is one of ~1000 in a list. Currently each instance of mainViewModel
also has an instance of innerViewModel
that is almost never used. Is there a standard way of lazily instantiating the innerViewModel
such that it is created only when it's view becomes visible? The normal approach of lazily instantiating does not work, since innerViewModel
is used in a binding.
Perhaps there is a better approach to housing a rarely seen control within another one?