Suppose I have a ViewModel with Event Loaded. I want to release the the handler immediately after hook it up. It means only hookup one time. I want to use anonymous in following way:
EventHandler handler = (s, e) =>
{
//......
vm.Loaded -= handler;;
};
vm.Loaded += handler;
it is not working. I don’t want to use named handler separately. What’s the solution for this case?
It should work if you declare the EventHandler first: