WPF Team with Click Event Handler

When I use Command in a Button control, the event handler that connects to the Click event will never raise,

How can I use Command and handle a Click event handler?

+7
command wpf
source share
3 answers

You can attach ICommand to another property and execute it from the Click handler.

 <Button x:Name="MyButton" Tag="{x:Static ApplicationCommands.Stop}" Click="MyButton_Click" /> 

and in the handler:

 private void MyButton_Click(object sender, RoutedEventArgs e) { var button = sender as Button; if (button != null) { var command = button.Tag as ICommand; if (command != null) command.Execute(button.CommandParameter); } } 

You will also need to do extra work if you want to keep the command disconnect behavior.

+17
source share
0
source share

The team is a kind of weekly event. Thinks good of teams that you do not need to use events. In fact, you do not need to use code and events at all if you use the Viewmodel template. See Relay Commands: http://blog.galasoft.ch/archive/2009/09/26/using-relaycommands-in-silverlight-and-wpf.aspx

-3
source share

All Articles