Lazy WPF Binding

I have an Expander from WPF (and using Entity Framework 4 and the MVVM template) that contains a ContentControl bound to some internal ViewModel . All I want is to link this LAZILY content control . That is, I want my ViewModel be "get" when Expander open.

How to do it? How to make complex windows with internal ViewModels faster?

+4
source share
2 answers

You can add the IsExpanded property to your ViewModel, associate an expander with it, and accept the value of this property when you return the contents of the ContentControl :

 private bool _isExpanded; public bool IsExpanded { get { return _isExpanded; } set { _isExpanded = value; OnPropertyChange("IsExpanded"); OnPropertyChange("Content"); } } public SomeType Content { get { if (!_isExpanded) return null; return LoadContent(); } } 
+4
source

Another option, similar to the above, could be to create an ObservableCollection, but only fill it when you first open the expander.

0
source

All Articles