WPFコマンドのルーティングを拡張して、フォーカスされたフィールドでコマンドを呼び出すことができるかどうかを確認したり、そのためのフックはありますか?たぶんあなたはそれがうまくいくかどうか分からないかもしれませんが、ネット上のどこかで似たようなものを見て、リンクを救うことができますか?例えばWPFルーティングコマンドの書き換え方法
抽象例
私はサイドパネルとパネルで、テキストエディタを書くことになる場合、フォーカスを持っているでしょう。 Ctrl + Gを押すと、パネルにコマンドバインディングとフォーカス(通常のWPFの動作)があるため、いくつかのコマンドが呼び出されます。また、Ctrl + Hキーを押しても、このパネルには呼び出されたコマンドにコマンドバインディングがありません。この場合、ルーティングエンジンをテキストエディタに切り替えて、同じコマンドをバブルすることが望ましいでしょう。
実例
私が貼り付け言いますが、フォーカスがサイドパネルにあるメニュー項目を持っています。メニューコマンドを押すと、パネルにバインドされたコマンドが実行されます。パネルにバインドされた適切なコマンドがないとします。この場合、テキストエディタに貼り付けたいと思います。
コード
このコードは、多かれ少なかれ、このシナリオを表します。私はこれが解決することができた道をCommandBinding_Executed_1
Window1.xaml
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1">
<StackPanel>
<TextBox x:Name="textBlock1">
<TextBox.CommandBindings>
<CommandBinding Command="local:Window1.TestCommand" Executed="CommandBinding_Executed_1" />
<CommandBinding Command="local:Window1.ForwardedTestCommand" Executed="CommandBinding_Executed_1" />
</TextBox.CommandBindings>
</TextBox>
<TextBox x:Name="textBlock2">
<TextBox.CommandBindings>
<CommandBinding Command="local:Window1.TestCommand" Executed="CommandBinding_Executed_2" />
</TextBox.CommandBindings>
<TextBox.InputBindings>
<KeyBinding Command="local:Window1.TestCommand" Gesture="Ctrl+G" />
<KeyBinding Command="local:Window1.ForwardedTestCommand" Gesture="Ctrl+H" />
</TextBox.InputBindings>
</TextBox>
</StackPanel>
</Window>
Window1.xaml.cs
using System.Windows;
using System.Windows.Input;
namespace WpfApplication1
{
public partial class Window1 : Window
{
public static RoutedUICommand TestCommand = new RoutedUICommand("TestCommand", "TestCommand", typeof(Window1));
public static RoutedUICommand ForwardedTestCommand = new RoutedUICommand("ForwardedTestCommand", "ForwardedTestCommand", typeof(Window1));
public Window1()
{
InitializeComponent();
}
private void CommandBinding_Executed_1(object sender, ExecutedRoutedEventArgs e)
{
MessageBox.Show("CommandBinding_Executed_1");
}
private void CommandBinding_Executed_2(object sender, ExecutedRoutedEventArgs e)
{
MessageBox.Show("CommandBinding_Executed_2");
}
}
}