Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Assuiming that you want to fire the event from your Custom Control, while clicking on the checkBox , and handling it in your implementing class, the following should work.</p> <p>First of all try to remove the template binding with event, though we expect it may work as it works templateBinding DependencyProperty</p> <p>So your XAML will look something as below:</p> <pre><code>&lt;DataTemplate&gt; &lt;...&gt; &lt;CheckBox x:Name="myCheckBox" /&gt; &lt;...&gt; &lt;/DataTemplate&gt; </code></pre> <p>Now You have to access your checkBox from generic.cs as below:</p> <pre><code> public override void OnApplyTemplate() { base.OnApplyTemplate(); CheckBox myCheckBox= GetTemplateChild("myCheckBox") as CheckBox; } </code></pre> <p>Now You just need to add a event to your Control.</p> <pre><code>public event EventHandler checkBoxChecked; </code></pre> <p>Now this are typically implemented like this:-</p> <pre><code> protected virtual void onCheckBoxChecked(EventArgs e) { var handler = checkBoxChecked; if (handler != null) handler(this, e); } </code></pre> <p>Now in your existing checked events:-</p> <pre><code>myCheckBox.Checked+= (obj, Args) =&gt; { onCheckBoxChecked(EventArgs.Empty); } </code></pre> <p>Now in your consuming code or Implementing Application you can do this sort of thing(Assuming your CustomControl Name is myCustomControl):-</p> <pre><code>myCustomControl.checkBoxChecked+=(s, args) =&gt; { /* Your Code Here*/ }; </code></pre> <p>Hope this is what you were trying to acomlish. If need anything esle , letz discuss here.</p> <p><strong>Update</strong></p> <p>Well there is detailed discussion about onApplyTemplate and loading the controls and accessing the events outside that class:</p> <p>Have a look:</p> <p><a href="https://stackoverflow.com/questions/2690177/how-to-access-a-button-present-inside-a-custom-control-from-the-implementing-pag">How to Access a Button present inside a Custom Control, from the implementing page?</a></p>
 

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