In a WPF app I can move a UserControl from a ContentControl to another one in code like this:
myContentControl1.Content = null;
myContentControl2.Content = myUserControl;
The problem is that the UserControl that has been moved is a rather heavy one (consists of a lot of smaller controls). So the above operation takes a significant amount of time, almost as long as when I load the UserControl initially. It seems that every element in that UserControl goes through processing to be moved under another ContentControl.
Is there a more efficient and faster method of placing a UserControl under another parent (in my case a ContentControl) as its child (without the need for UI thread to process all its elements every time)? (Dynamically, in code-behind)
Instead of switching a
ContentControl‘s content between your twoUserControl‘s, put bothUserControl‘s in aGridand toggle theirVisibility. While showing one with current data, update the other, invisible one in the background. When updating is done, toggle both control’s visibility fromVisibletoHiddenand vice versa. Don’t useCollapsed, since that would force a new layout cycle.Putting both in a
Gridwithout specifyingRoworColumnmakes them lie above each other.