![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| Guest | Is there an event that real fires for sure only once UserControl L 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 |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Is there an event that real fires for sure only once UserControlL Hello, Concerning the above it is answered in large part in the MSDN article "Object Lifetime Events" I quote from this articel below: the Loaded event is raised as a coordinated effort throughout the entire element tree (specifically, the logical tree). When all elements in the tree are in a state where they are considered loaded, the Loaded event is first raised on the root element. The Loaded event is then raised successively on each child element. Note: This behavior might superficially resemble bubbling for a routed event. However, no information is carried from event to event. Each element always has the opportunity to handle its Loaded event, and marking the event data as handled has no effect beyond that element. |
My System Specs![]() |
| | #3 (permalink) |
| Guest | RE: Is there an event that real fires for sure only once UserControl L Hello, Concerning the above it is answered in large part in the MSDN article "Object Lifetime Events" I quote from this articel below: the Loaded event is raised as a coordinated effort throughout the entire element tree (specifically, the logical tree). When all elements in the tree are in a state where they are considered loaded, the Loaded event is first raised on the root element. The Loaded event is then raised successively on each child element. Note: This behavior might superficially resemble bubbling for a routed event. However, no information is carried from event to event. Each element always has the opportunity to handle its Loaded event, and marking the event data as handled has no effect beyond that element. -- Regards, Paul "Schwartzenberg" wrote: Quote: > 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 > > > > > |
My System Specs![]() |
| | #4 (permalink) |
| Guest | RE: Is there an event that real fires for sure only once UserControl L Hello, Concerning the above it is answered in large part in the MSDN article "Object Lifetime Events" I quote from this articel below: the Loaded event is raised as a coordinated effort throughout the entire element tree (specifically, the logical tree). When all elements in the tree are in a state where they are considered loaded, the Loaded event is first raised on the root element. The Loaded event is then raised successively on each child element. Note: This behavior might superficially resemble bubbling for a routed event. However, no information is carried from event to event. Each element always has the opportunity to handle its Loaded event, and marking the event data as handled has no effect beyond that element. -- Regards, Paul "Schwartzenberg" wrote: Quote: > 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 > > > > > |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| leave event fires disabling textbox below -cursor stays in 1st tex | .NET General | |||
| Windows Defender: Event 3004 never fires | Vista security | |||