您可以使用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
}
我可以看看這是怎麼回事,但它不起作用。 MainRegion.xaml命令綁定不與RibbonRegion命令進行通信。 我的意思是MainRegion.xaml.cs'OnTestExecute'從來沒有從RibbonRegion的角度來評估,因此RibbonButton總是被禁用。 – TrialAndError 2012-08-27 14:54:58
@TrialAndError:你有沒有找到更好的解決方案?如果是這樣,請回答你的問題讓我們知道:) – Jalal 2013-02-01 13:01:11