Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Window.Loaded

 
 
Old 02-23-2006   #1 (permalink)
Erno


 
 

Window.Loaded

Hi!

I noticed that my Window.Loaded eventhandler is triggered twice. When I
remove the event wiring from the Xaml the handler is not being called so I
know I didn't trigger the Loaded method by hand.

Anybody any clue or suggestion what is going on?

Thanks!

Erno
----
WPF tutorials: http://blogs.infosupport.com/ernow/articles/1878.aspx




My System SpecsSystem Spec
Old 02-24-2006   #2 (permalink)
Greg K


 
 

Re: Window.Loaded

I'm seeing something similar to this, too, for example, in MyApp.xaml
with the following code:

<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles.xaml"/>
..
..
..

Error at element 'ResourceDictionary' in markup file 'Window1.xaml' :
Item has already been added. Key in dictionary: 'lbiDataTemplate1' Key
being added: 'lbiDataTemplate1'.

I've found that if I rebuild the project, everything works and I don't
get the error. It can happen after a minor edit of an unrelated XAML
file in the project.

Greg


Erno wrote:
> Hi!
>
> I noticed that my Window.Loaded eventhandler is triggered twice. When I
> remove the event wiring from the Xaml the handler is not being called so I
> know I didn't trigger the Loaded method by hand.
>
> Anybody any clue or suggestion what is going on?
>
> Thanks!
>
> Erno
> ----
> WPF tutorials: http://blogs.infosupport.com/ernow/articles/1878.aspx
>
>
>

My System SpecsSystem Spec
Old 02-24-2006   #3 (permalink)
Greg K


 
 

Re: Window.Loaded

Solved, I think. I forgot to REMOVE one of the old "<?Mapping" PIs from
a XAML file after making the described changes for Feb CTP.

Greg

Greg K wrote:
> I'm seeing something similar to this, too, for example, in MyApp.xaml
> with the following code:
>
> <Application.Resources>
> <ResourceDictionary>
> <ResourceDictionary.MergedDictionaries>
> <ResourceDictionary Source="Styles.xaml"/>
> ..
> ..
> ..
>
> Error at element 'ResourceDictionary' in markup file 'Window1.xaml' :
> Item has already been added. Key in dictionary: 'lbiDataTemplate1' Key
> being added: 'lbiDataTemplate1'.
>
> I've found that if I rebuild the project, everything works and I don't
> get the error. It can happen after a minor edit of an unrelated XAML
> file in the project.
>
> Greg
>
>
> Erno wrote:
>> Hi!
>>
>> I noticed that my Window.Loaded eventhandler is triggered twice. When
>> I remove the event wiring from the Xaml the handler is not being
>> called so I know I didn't trigger the Loaded method by hand.
>>
>> Anybody any clue or suggestion what is going on?
>>
>> Thanks!
>>
>> Erno
>> ----
>> WPF tutorials: http://blogs.infosupport.com/ernow/articles/1878.aspx
>>
>>
>>

My System SpecsSystem Spec
Old 02-24-2006   #4 (permalink)
Erno


 
 

Re: Window.Loaded

Greg,

I don't see how this relates to 'my' problem...

Cheers

Erno

"Greg K" <gregk@smudgeybear.com> wrote in message
news:%23muyfKIOGHA.1288@TK2MSFTNGP09.phx.gbl...
> I'm seeing something similar to this, too, for example, in MyApp.xaml with
> the following code:
>
> <Application.Resources>
> <ResourceDictionary>
> <ResourceDictionary.MergedDictionaries>
> <ResourceDictionary Source="Styles.xaml"/>
> .
> .
> .
>
> Error at element 'ResourceDictionary' in markup file 'Window1.xaml' : Item
> has already been added. Key in dictionary: 'lbiDataTemplate1' Key being
> added: 'lbiDataTemplate1'.
>
> I've found that if I rebuild the project, everything works and I don't get
> the error. It can happen after a minor edit of an unrelated XAML file in
> the project.
>
> Greg
>
>
> Erno wrote:
>> Hi!
>>
>> I noticed that my Window.Loaded eventhandler is triggered twice. When I
>> remove the event wiring from the Xaml the handler is not being called so
>> I know I didn't trigger the Loaded method by hand.
>>
>> Anybody any clue or suggestion what is going on?
>>
>> Thanks!
>>
>> Erno
>> ----
>> WPF tutorials: http://blogs.infosupport.com/ernow/articles/1878.aspx
>>
>>


My System SpecsSystem Spec
Old 02-24-2006   #5 (permalink)
Greg K


 
 

Re: Window.Loaded

Erno,

Granted it may not be related, but you mentioned that your Window.Loaded
event handler was being called twice, and from the error message I
posted, my DataTemplate is being merged twice into the
ResourceDictionary in Application.Resources. Both your problem and mine
appear to happen on startup as well, and I assume your app was working
as well unchanged with Jan/Dec CTP.

If you leave the Loaded event wired, does the problem still occur if you
do a complete project rebuild, then run it ?

Greg

Erno wrote:
> Greg,
>
> I don't see how this relates to 'my' problem...
>
> Cheers
>
> Erno
>
> "Greg K" <gregk@smudgeybear.com> wrote in message
> news:%23muyfKIOGHA.1288@TK2MSFTNGP09.phx.gbl...
>> I'm seeing something similar to this, too, for example, in MyApp.xaml with
>> the following code:
>>
>> <Application.Resources>
>> <ResourceDictionary>
>> <ResourceDictionary.MergedDictionaries>
>> <ResourceDictionary Source="Styles.xaml"/>
>> .
>> .
>> .
>>
>> Error at element 'ResourceDictionary' in markup file 'Window1.xaml' : Item
>> has already been added. Key in dictionary: 'lbiDataTemplate1' Key being
>> added: 'lbiDataTemplate1'.
>>
>> I've found that if I rebuild the project, everything works and I don't get
>> the error. It can happen after a minor edit of an unrelated XAML file in
>> the project.
>>
>> Greg
>>
>>
>> Erno wrote:
>>> Hi!
>>>
>>> I noticed that my Window.Loaded eventhandler is triggered twice. When I
>>> remove the event wiring from the Xaml the handler is not being called so
>>> I know I didn't trigger the Loaded method by hand.
>>>
>>> Anybody any clue or suggestion what is going on?
>>>
>>> Thanks!
>>>
>>> Erno
>>> ----
>>> WPF tutorials: http://blogs.infosupport.com/ernow/articles/1878.aspx
>>>
>>>

>

My System SpecsSystem Spec
Old 02-24-2006   #6 (permalink)
Erno


 
 

Re: Window.Loaded

Wow! A full rebuild cleared that up!

Ok, I'm switching to Always full rebuild...

Thanks Greg!


Erno
----
WPF tutorials: http://blogs.infosupport.com/ernow/articles/1878.aspx




"Greg K" <gregk@smudgeybear.com> wrote in message
news:%23oSgCNMOGHA.1460@TK2MSFTNGP10.phx.gbl...
> Erno,
>
> Granted it may not be related, but you mentioned that your Window.Loaded
> event handler was being called twice, and from the error message I posted,
> my DataTemplate is being merged twice into the ResourceDictionary in
> Application.Resources. Both your problem and mine appear to happen on
> startup as well, and I assume your app was working as well unchanged with
> Jan/Dec CTP.
>
> If you leave the Loaded event wired, does the problem still occur if you
> do a complete project rebuild, then run it ?
>
> Greg
>
> Erno wrote:
>> Greg,
>>
>> I don't see how this relates to 'my' problem...
>>
>> Cheers
>>
>> Erno
>>
>> "Greg K" <gregk@smudgeybear.com> wrote in message
>> news:%23muyfKIOGHA.1288@TK2MSFTNGP09.phx.gbl...
>>> I'm seeing something similar to this, too, for example, in MyApp.xaml
>>> with the following code:
>>>
>>> <Application.Resources>
>>> <ResourceDictionary>
>>> <ResourceDictionary.MergedDictionaries>
>>> <ResourceDictionary Source="Styles.xaml"/>
>>> .
>>> .
>>> .
>>>
>>> Error at element 'ResourceDictionary' in markup file 'Window1.xaml' :
>>> Item has already been added. Key in dictionary: 'lbiDataTemplate1' Key
>>> being added: 'lbiDataTemplate1'.
>>>
>>> I've found that if I rebuild the project, everything works and I don't
>>> get the error. It can happen after a minor edit of an unrelated XAML
>>> file in the project.
>>>
>>> Greg
>>>
>>>
>>> Erno wrote:
>>>> Hi!
>>>>
>>>> I noticed that my Window.Loaded eventhandler is triggered twice. When I
>>>> remove the event wiring from the Xaml the handler is not being called
>>>> so I know I didn't trigger the Loaded method by hand.
>>>>
>>>> Anybody any clue or suggestion what is going on?
>>>>
>>>> Thanks!
>>>>
>>>> Erno
>>>> ----
>>>> WPF tutorials: http://blogs.infosupport.com/ernow/articles/1878.aspx
>>>>
>>>>

>>



My System SpecsSystem Spec
Old 02-24-2006   #7 (permalink)
damien morton


 
 

Re: Window.Loaded

I was getting the same problem.

you need to set e.Handled=true at the end of your OnLoaded handler.

private void OnLoaded(object sender, RoutedEventArgs e)
{
...
e.Handled = true;
}

My System SpecsSystem Spec
Old 02-24-2006   #8 (permalink)
Erno


 
 

Re: Window.Loaded

I think that this is a hack or work-around and definitly not the way to do
this.

Full rebuild fixed it for me.


Erno
----
WPF tutorials: http://blogs.infosupport.com/ernow/articles/1878.aspx



"damien morton" <damien.morton@gmail.com> wrote in message
news:1140805758.876996.40500@e56g2000cwe.googlegroups.com...
>I was getting the same problem.
>
> you need to set e.Handled=true at the end of your OnLoaded handler.
>
> private void OnLoaded(object sender, RoutedEventArgs e)
> {
> ...
> e.Handled = true;
> }
>



My System SpecsSystem Spec
Old 02-25-2006   #9 (permalink)
damien morton


 
 

Re: Window.Loaded

Full rebuild didnt seem to stop the two OnLoaded events for me.

My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Can't get on net after update loaded Vista General
No loaded with 64 bit? Vista General
COM Add-in could not be loaded after UAC is disabled Vista security
100% CPU loaded Vista performance & maintenance
100% CPU loaded Vista performance & maintenance


Vista Forums 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 Ltd

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