tags:

views:

107

answers:

1

Hi,

I'm loading a XAML file with XamlReader and setting the returning object to the window's Content property. While this seems to work well, it doesn't quite do what I expect. If the window's original XAML contains keybindings or buttons, they seem to still exist. Keybindings still work and any Button objects in code are still valid. I would've expected everything to be destroyed since I've replaced them with a new XAML but that's not the case.

So what exactly does setting Content do? What does it not do?

Thanks!

+1  A: 

Changing the Content property you are just switching the object that represents the Window's content, all the element tree will be maintained, including bindings. In WPF you can't explicitily dispose a control because there is nothing to dispose, I mean, no unmanaged resources to release. If don't refer this controls later, the GC will clean them. For keybindings you will have to remove them programatically, iterating through window controls or calling the respective application command cleaner, for example:

ApplicationCommands.Close.InputGestures.Clear();

Hope this helps!

Eduardo Cobuci