Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
misc
exam.security
microsoft_update_catalog
msdn.annotations
msdn.drgui.discussion
msdn.duwamish
msdn.general
msdn.magazine
msdn.soaptoolkit
msdn.webservices
msdntraining
opsmgr.connectors
opsmgr.sp1
technet
technet.howtofeedback
technet.howtoneeds
technet.magazine
technet.technettalks
  
 
date: Wed, 21 May 2008 02:44:03 -0700,    group: microsoft.public.msdn.drgui.drguidotnet.discussion        back       


can code execute just once when a (contained) control Loads?   
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
date: Wed, 21 May 2008 02:44:03 -0700   author:   Schwartzenberg ve_xx

RE: can code execute just once when a (contained) control Loads?   
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
date: Wed, 21 May 2008 02:52:03 -0700   author:   Schwartzenberg ve_xx

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us