#1,074 – Attached Event Syntax

Attached events allow attaching a handler for an event that is defined in an element other than the one adding the handler.  For example, a StackPanel might define a handler for the Click event that is defined in ButtonBase.

When defining handlers in XAML, the event name is used by itself if that event is defined for the element raising the event.

        <Button Content="Click Me" Click="Button_Click"/>

When defining a handler on an element that does not define the handler’s event, you prefix the event name with the name of the class that defines the event.

    <StackPanel Button.Click="StackPanel_Button_Click">

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #1,074 – Attached Event Syntax

  1. Pingback: Dew Drop – May 16, 2014 (#1778) | Morning Dew

Leave a comment