How can I have a Command that can be called from both a Window and a UserControl (by hitting a button in either) that uses the same execute and can-execute methods? It seems like if I have the following in my UserControl's XAML, it requires myCommandHandler
and canExecuteMyCommand
to be in my UserControl class:
<CommandBinding Command="{x:Static local:MyUserControl.MyCommand}"
Executed="myCommandHandler"
CanExecute="canExecuteMyCommand"/>
Then if I want to use the same Command in my Window, I again need myCommandHandler
and canExecuteMyCommand
defined in my Window's class. How can I define a Command such that both my UserControl and Window can access it, but myCommandHandler
and canExecuteMyCommand
are only defined in one class? Do I need to create my own command class instead of declaring a static RoutedCommand
field in MyUserControl
?