ScintillaNet和RoutedCommands

时间:2012-10-26 16:51:54

标签: c# wpf command scintilla

我在C#WPF应用程序中使用ScintillaNet编辑控件。在我的主窗口中,我有一些RoutedCommands设置。 ScintillaNet控件托管在WindowsFormsHost中。当ScintillaNet控件具有焦点时,RoutedCommands不起作用。

我尝试捕获关键笔划并手动执行RoutedCommands但CanExecute总是失败:

WindowsFormsHost wfh = new WindowsFormsHost();
Scintilla editor = new Scintilla();
wfh.Child = editor;
wfh.Child.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(Child_PreviewKeyDown);

....

void Child_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
    if (e.KeyData == Keys.F5)
        // Window1 is the main window class
        // handle is a reference to the main window
        if (Window1.CmdRun.CanExecute(wfh, handle)) {
            Window1.CmdRun.Execute(wfh, handle);
        }
        else {
            Console.WriteLine("CANT EXECUTE");
        }
    }
}

有谁能告诉我如何正确地做到这一点?

由于

0 个答案:

没有答案