Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Take a look at <a href="http://msdn.microsoft.com/en-us/library/system.windows.input.routedcommand.aspx" rel="noreferrer">RoutedCommand</a>s.</p> <p>Define your command in myclass somewhere as follows:</p> <pre><code> public static readonly RoutedCommand Login = new RoutedCommand(); </code></pre> <p>Now define your button with this command:</p> <pre><code> &lt;Button Command="{x:Static myclass.Login}" /&gt; </code></pre> <p>You can use CommandParameter for extra information..</p> <p>Now last but not least, start listening to your command:</p> <p>In the constructor of the class you wish to do some nice stuff, you place:</p> <pre><code> CommandBindings.Add(new CommandBinding(myclass.Login, ExecuteLogin)); </code></pre> <p>or in XAML:</p> <pre><code> &lt;UserControl.CommandBindings&gt; &lt;CommandBinding Command="{x:Static myclass.Login}" Executed="ExecuteLogin" /&gt; &lt;/UserControl.CommandBindings&gt; </code></pre> <p>And you implement the delegate the CommandBinding needs:</p> <pre><code> private void ExecuteLogin(object sender, ExecutedRoutedEventArgs e) { //Your code goes here... e has your parameter! } </code></pre> <p>You can start listening to this command everywhere in your visual tree!</p> <p>Hope this helps</p> <p>PS You can also define the CommandBinding with a CanExecute delegate which will even disable your command if the CanExecute says so :)</p> <p>PPS Here is another example: <a href="http://www.wpfwiki.com/Default.aspx?Page=WPF%20Q13.8&amp;AspxAutoDetectCookieSupport=1" rel="noreferrer">RoutedCommands in WPF</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