The Loaded UserControl at the bottom of the Control tree is fired for every time the Loaded event is fired in every containing (parent) Control. The Loaded event is not routed so setting the following on one of the parent controls, private void OnLoaded(object sender, RoutedEventArgs e) { e.Handled = true; } has no effect. Following invocations of OnLoaded in contained UserControls have e.Handle = = false. Have a WPF UserControl contained within a UserControl that also is contained within a UserControl. Etc. It seems that the Loaded event of the UserControl at the bottom of the tree is triggered multiple time for each containment. But i'd like code in it to execute only once. It's possible (say) to put a private boolean field ('hasLoaded') in my UserControl and set it to 'false' in the first entry to OnLoad and then 'true' in the UnLoad handler. And then excecute code in OnLoaded only for when hasLoaded==true. But isnt there some better way to make sure that code executes just once when a control Loads! Loaded is one of the UserControls Object LifeTime Events ... so it doesnt seem to be routed. Is there another event i should handle in this situation instead of Loaded? Regards, Paul -- Regards, Paul
I am rewriting the question here: It seems that the Loaded event of the UserControl at the bottom of the tree is triggered multiple time for each containment. But i'd like code in it to execute only once. It's possible (say) to put a private boolean field ('hasLoaded') in my UserControl and set it to 'false' in the first entry to OnLoad and then 'true' in the UnLoad handler. And then excecute code in OnLoaded only for when hasLoaded==true. But isnt there some better way to make sure that code executes just once when a control Loads!? Loaded is one of the UserControls Object LifeTime Events ... so it doesnt seem to be routed. Is there another event i should handle in this situation instead of Loaded? Regards, Paul