コマンドにバインドされたズームを減らすためのデフォルトのツールバーボタンを備えたreportViewerがありますNavigationCommands.DecreaseZoom
。ある状況でそれを無効にしたいので、メソッドをバインドCanExecute
して、そのコマンドに対してfalseを返します。これは完全に正常に機能し、期待どおりにボタンを無効にします。ただし、ショートカットキーを使用すると、ズームアウトは機能します"Ctrl + Subtract key"
。CanExecuteが機能すると仮定して同じコマンドを設定しようとしましKeyBinding
たが、機能しません。以来、CanExecuteはKeyBindingで提供されていません。誰かが、永続的ではなく、特定の状況(CanExecuteのロジック)でKeyGesture「Ctrl-」を無効にする方法を提案できますか?
関連コード-
<DocumentViewer Name="documentViewer1"
Margin="0,0,0,30"
Style="{DynamicResource DocumentViewerStyle1}">
<DocumentViewer.CommandBindings>
<CommandBinding Command="NavigationCommands.DecreaseZoom"
CanExecute="DecreaseZoom_CanExecute" />
</DocumentViewer.CommandBindings>
<DocumentViewer.InputBindings>
<KeyBinding Command="NavigationCommands.DecreaseZoom"
Key="OemMinus"
Modifiers="Control" />
</DocumentViewer.InputBindings>
</DocumentViewer>
背後にあるコード-
private void DecreaseZoom_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
if (((DocumentViewer)e.Source).PageViews.Count >= 3)
{
e.CanExecute = false;
e.ContinueRouting = false;
e.Handled = true;
}
}