When I’m to subscribe to event, i’m coding like that: (in visual studio 2010)
1. I Write down like following code:
this.Loaded +=
2. I Press tab key.
3. A IDE fill a below code automatic:
this.Loaded+=new RoutedEventHandler(someClass_Loaded);
4. But the method someClass was not exist yet. so I write a method like following code:
private void someClass_Loaded()
{
}
5. But signiture of someClass was not defined properly yet. so I set cursor on the delegate, “RoutedEventHandler”.
6. I press F12. and then IDE showing me a define of the RoutedEventHandler.
namespace System.Windows
{
[...]public delegate void RoutedEventHandler(object sender, RoutedEventArgs e);
}
7. copy a arguments of the RoutedEventHandler.
8. I paste it to the method someClass_Loaded
private void someClass_Loaded(object sender, RoutedEventArgs e)
{
}
Is it best coding practice?
ps. When I subscribe a event by anonymous method, I do like this.
Try doing this twice. Not only will Visual Studio expand the new event handler assignment, it will also create a stub method in the class that has the correct name and proper signature.