Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm going to assume this has nothing to do with WPF, this is a silverlight question.</p> <p>First of all you can't simply add an <code>Event</code> to an existing control. After all you are adding attached <code>Properties</code> whereas events are handled differently, they're not properties.</p> <p>You need to create a new type which has this event then create an attached property of this type. </p> <p>Here is a basic type that simply has an event:-</p> <pre><code>public class MyEventer { public event EventHandler MyEvent; // What would call this?? protected void OnMyEvent(EventArgs e) { if (MyEvent != null) MyEvent(this, e); } } </code></pre> <p>Now we create an attached property which has <code>MyEventer</code> as its property, I prefer to place these in a separate static class.</p> <pre><code>public static class MyProps { public static MyEventer GetEventer(DependencyObject obj) { return (MyEventer)obj.GetValue(EventerProperty ); } public static void SetEventer(DependencyObject obj, MyEventer value) { obj.SetValue(EventerProperty , value); } public static readonly DependencyProperty EventerProperty = DepencencyProperty.RegisterAttached("Eventer", typeof(MyEventer), typeof(MyProps), null) } } </code></pre> <p>Now you attach this to a control like this:-</p> <pre><code>&lt;Border ...&gt; &lt;custom:MyProps.Eventer&gt; &lt;custom:MyEventer MyEvent="someHandler" /&gt; &lt;/custom:MyProps.Eventer&gt; &lt;/Border&gt; </code></pre> <p>If you compile the project before writing this xaml you'll note that Visual Studio will offer you the option for it to create the event handler in the code behind for you.</p> <p>Of course this still leaves a significant question: How did you intend to cause the event to fire?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload