1
新的WPF ......正在读这WPF Routed Command with Bindings per-Tab和很接近得到它的工作。WPF ComamndBinding帮助上菜单项
直到我RuleTab(TabItem的)被选择,但不是我的弹出查找对话框它显示在菜单上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>
然后引用Command =在我的MenuItem中查找。
建议是什么?问题是什么? – DHN 2011-02-09 20:38:22