I have Expander
from WPF (and using Entity Framework 4 and MVVM pattern) which contains ContentControl
bound to some inner ViewModel
. All I want is to bind this content control LAZILY. That is I want my ViewModel
to be "get" when the Expander
is opened.
How to do that? How to make complex windows with inner ViewModels
faster?
You could add an IsExpanded
property to your ViewModel, bind the expander to it, and take the value of that property into account when returning the content 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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With