Why not systematically attach event in WPF instead of using delegate ?
- by user310291
For a button to handle event, we can add a delegate to the click property of the button:
this.button1.Click += new System.EventHandler(this.button1_Click);
But in WPF contrary to Winform, you can also attach a handler
http://msdn.microsoft.com/en-us/magazine/cc785480.aspx
So why not do so for the button ? Is performance better in first case maybe ?
Update: I mean this
Attached Events
In order to enable elements to handle events that are declared in a different element, WPF supports something called attached events. Attached events are routed events that support a hookup in XAML on elements other than the type on which the event is declared. For example, if you want the Grid element to listen for a Button.Click event to bubble past, you would simply hook it up like the following:
<Grid Button.Click="myButton_Click"> <Button Name="myButton" >Click Me</Button> </Grid>
The resulting code in the compile-time-generated partial class now looks like this:
#line 5 "..\..\Window1.xaml" ((System.Windows.Controls.Grid)(target)).AddHandler( System.Windows.Controls.Primitives.ButtonBase.ClickEvent, new System.Windows.RoutedEventHandler(this.myButton_Click));