WPF の新機能...タブごとのバインドを使用してこの WPF Routed Command を読んでいて、それを機能させることに近づいています。
RuleTab (tabitem) が選択されるまで MenuItem は無効になりますが、検索ダイアログをポップするのではなく、メニューに System.Windows.Input.CommandBinding を表示します。私は何を間違っていますか?
XAML:
<MenuItem Header="_Find..." IsEnabled="{Binding ElementName=RuleTab, Path=IsSelected}" >
<CommandBinding Command="Find" Executed="ExecuteFind" CanExecute="Find_CanExecute" ></CommandBinding>
</MenuItem>
コード ビハインド:
private void ExecuteFind(object sender, ExecutedRoutedEventArgs e)
{
// Initiate FindDialog
FindDialog dlg = new FindDialog(this.RuleText);
// Configure the dialog box
dlg.Owner = this;
dlg.TextFound += new TextFoundEventHandler(dlg_TextFound);
// Open the dialog box modally
dlg.Show();
}
void dlg_TextFound(object sender, EventArgs e)
{
// Get the find dialog box that raised the event
FindDialog dlg = (FindDialog)sender;
// Get find results and select found text
this.RuleText.Select(dlg.Index, dlg.Length);
this.RuleText.Focus();
}
private void Find_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = RuleTab.IsSelected;
}
どんな提案でも大歓迎です!
理解した!回答者に感謝します。私がしなければならなかったのは、コマンドバインディングを次の場所に移動することだけでした:
<Window.CommandBindings>
<CommandBinding Command="Find" Executed="ExecuteFind" CanExecute="Find_CanExecute" ></CommandBinding>
</Window.CommandBindings>
次に、MenuItem で Command=Find を参照します。