Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have a feeling, that you're trying to mimic EventSetter behaviour. If I'm right, please just take a look on this simple example:</p> <pre><code> &lt;Style TargetType="{x:Type Button}" x:Key="SomeID"&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="IsMouseOver" Value="True"&gt; &lt;Setter Property="Cursor" Value="Hand"&gt;&lt;/Setter&gt; &lt;Setter Property="FontWeight" Value="Bold"&gt;&lt;/Setter&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;EventSetter Event="MouseUp" Handler="DoSomething_Click"&gt;&lt;/EventSetter&gt; &lt;/Style&gt; </code></pre> <p>This code assigns your custom event to some text block's regular action directly from XAML (you don't have to pollute your code behind with accessing controls' properties).</p> <p>I hope this is helpful, but if not, please give me a shout.</p> <p><strong>Edit:</strong></p> <p>Sorry for not being perfectly clear (this was just a quickly pasted code snippet). Please have a look on a complete example:</p> <p>Styles for your next/previous buttons:</p> <pre><code>&lt;Style TargetType="{x:Type Button}" x:Key="PreviousButtonstyle"&gt; &lt;EventSetter Event="Click" Handler="OnMovedPrevious"&gt;&lt;/EventSetter&gt; &lt;/Style&gt; &lt;Style TargetType="{x:Type Button}" x:Key="NextButtonstyle"&gt; &lt;EventSetter Event="Click" Handler="OnMovedNext"&gt;&lt;/EventSetter&gt; &lt;/Style&gt; </code></pre> <p>Code behind:</p> <pre><code> public event EventHandler MovedPrevious; public event EventHandler MovedNext; protected void OnMovedPrevious(object sender, RoutedEventArgs e) { if (MovedPrevious != null) { MovedPrevious(this, e); } } protected void OnMovedNext(object sender, RoutedEventArgs e) { if (MovedNext != null) { MovedNext(this, e); } } </code></pre> <p>Since now on you can access <strong>OnMovedNext</strong> and <strong>OnMovedPrevious</strong> directly from your control's handling conrol/whatever just as Anthony posted.</p> <p>Sorry if my previous answer was confusing, but it supposed to be just an inspiration what to do :) </p> <p><strong>Edit:</strong></p> <p>I haven't noticed that this regards only Silverlight for which I apologize :) But, it works perfectly for WPF if you wish to try.</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