Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

Is there an event that real fires for sure only once UserControl L

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 05-21-2008   #1 (permalink)
Schwartzenberg
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 SpecsSystem Spec
Old 05-23-2008   #2 (permalink)
Schwartzberg
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 SpecsSystem Spec
Old 05-23-2008   #3 (permalink)
Schwartzenberg
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 SpecsSystem Spec
Old 05-23-2008   #4 (permalink)
Schwartzenberg
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 SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows Defender: Event 3004 never fires ruisu Vista security 0 08-22-2008 06:53 PM
UserControl inside another UserControl with WYSIWYG jan.bannister@gmail.com Avalon 1 02-07-2007 06:42 AM
Templated ComboBox fires SelectionChanged twice Keith Patrick Avalon 0 01-04-2007 11:08 AM
How to bind to a usercontrol property from inside this usercontrol Pon Avalon 4 11-13-2006 08:38 AM
WPF UserControl in a Forms.UserControl MichaelG Avalon 2 01-10-2006 03:52 PM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51