你可以使用一个System.Windows.Input.RoutedUICommand
首先,您需要如下声明您的命令:
public static class Commands
{
public static readonly RoutedUICommand TestCommand = new RoutedUICommand("Test Command",
"Test Command", typeof(Commands));
}
然后在您的 RibbonRegion xaml 中:
<my:RibbonButton Command="{x:Static cmd:Commands.TestCommand}" ...
然后在您的 MainRegion xaml 中:
<UserControl.CommandBindings>
<CommandBinding CanExecute="OnTestCanExecute"
Command="{x:Static cmd:Commands.TestCommand}"
Executed="OnTestExecute" />
</UserControl.CommandBindings>
然后在您的 xaml.cs 中:
public void OnTestRouteCanExecute(object sender, System.Windows.Input.CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
public void OnTestRouteExecute(object sender, System.Windows.Input.ExecutedRoutedEventArgs e)
{
// do some stuff here
}