Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Routed event syntax [duplicate]

I have a question about Routed Events, I see in some documentation that when we define our own custom events, we add and remove handlers to it using the following code:

public event RoutedEventHandler CustomClick
{
    add { AddHandler(CustomClickEvent, value); }

    remove { RemoveHandler(CustomClickEvent, value); }
}

But my point is that this is neither looking like a Constructor syntax, nor a Property initialization syntax! also it is not a property get/set syntax (although it looks similar to that). I have read detailed C# documentation, but I don't see what kind of construct is this. Only in documentation about custom RoutedEvents, i see this code, but in normal C# tutorial/primer, I never see that this is a legal language construct. Can anybody explain to me this? or point me to a good documentation explaining this?

Thanks in advance.

like image 595
user2755525 Avatar asked Sep 20 '26 16:09

user2755525


1 Answers

They are "event accessors". They are the event equivalent of property syntax. They allow you to expose an event and change how it works .. without breaking the encapsulating classes contract (like properties).

See here for an explanation: http://msdn.microsoft.com/en-us/library/bb882534.aspx

like image 112
Simon Whitehead Avatar answered Sep 22 '26 06:09

Simon Whitehead



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!