Loaded event handler choice is presented

(mtiede) #1

When I create a WPF application and go to the window constructor and try to add a Loaded event handler, it used to get created as a choice in the popup at least when hitting Ctrl-SpaceBar. Now it doesn’t. Is that an oversight or bug?

Here is sample code:

   constructor Window1;
      Loaded += ;

It used to be that there would be a choice in the popup to create a method to handle the loaded event, like Window1_Loaded or something. And then when you chose that, it would generate the code with the proper arguments, etc.

In the past, there was a sort of maybe related problem while in Silverlight. Loaded default event handler doesn’t compile except in that the generated code wouldn’t compile.

(Carlo Kok) #2

hrmm I do see the item:



that said it seems to insert it wrong so I’ll log a bug.

(RemObjects) #3

Thanks, logged as bugs://81468

(mtiede) #4

Ok, I thought it used to, by default, make the routine be called like Window1_Loaded and that is what I was looking for. Perhaps that has changed. Or maybe that is just the way it worked in Silverlight.

Thanks for checking it out. When I tried the OnLoaded one, it didn’t work for me either. It created a method OnLoaded, but it wasn’t a method of the object class. In the interface section, it added a method ok, but the implementation section did have the class name. Just “method OnLoaded” etc. instead of “method Window1.OnLoaded”. When I told the class in the interface section to complete the class, it created the method properly. But then the OnLoaded that wasn’t part of the class was still there.

Hope that helps you while you are looking at that bit of code. (and I hope I was clear enough)

(Carlo Kok) #5

Yes. I logged the but because it didn’t properly create the method and could name it better.

(mtiede) #6

I’m not sure there is anything wrong with the OnLoaded. I just expected the old way. The old way was actually a little redundant. If the class is Window1, do we really need a Window1.Window1_Loaded? I’m not at all sure. I haven’t thought about such things for months. Maybe there could be some other object that also has a “Loaded” event. And in the class, if one is “OnLoaded”, then the new object’s method couldn’t be “OnLoaded” also. That is probably why the class was getting prefixed. That way you could have a bunch of different classes used by the Window class that each have their own Loaded event handler and there wouldn’t be as likely a name collision.

Just my rambling thoughts.