I have an entity class. This entity has lots of properties and entity’s data is shown to the user in several TabItems of a TabControl. I also implement MVVM approach.
When the screen is shown to the user first, I want to bind only the active tab page controls and as the user navigates through tab pages additional separate bindings will be incurred as-needed. How can I achieve that?
You don’t have anything to do, that’s the default behavior. The
DataTemplatefor aTabItemcontent won’t be instantiated until thisTabItemis selectedEDIT: here’s an example:
In the code above, the
TabControlwill pick the appropriateDataTemplatebased on the item type, and will render it only when that item is selected.EDIT 2: apparently you want to display the data of a single ViewModel on several pages. If you want the controls of each
TabItemto lazily instantiated, you need to use theContentTemplateproperty of eachTabItem: