George
George

Reputation: 160

Appropriate way to clear all of the content of a window

I am searching for a way to clear the whole content of a window in WPF. So far I couldn't find a way which suits my needs on the net. However I came up with this:

Let's say that I have MainWindow view, what I am doing is:

MainWindow.Content = null;
MainWindow.Content = new UserControl();

It does work but I am unsure whether this approach is safe and correct.

Upvotes: 1

Views: 2108

Answers (1)

dursk
dursk

Reputation: 4445

There's no need to set MainWindow.Content to null first.

All you have to do is:

MainWindow.Content = new UserControl();

and the GC will take care of the rest.

Upvotes: 4

Related Questions