MenuItem上的WPF ComamndBinding帮助

WPF的新用户......正在阅读这个带有Bindings per-Tab的WPF路由命令,并且接近它正在运行。 MenuItem被禁用,直到我的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>
然后在我的MenuItem中引用Command = Find。     
已邀请:
您会发现需要将CommandBinding添加到TabItem(根据链接的示例)。然后绑定你的MenuItem你应该使用
Command
属性,可能还有一个
CommandParameter
CommandTarget
(指向我期望的TabItem)。 例如,我在ContextMenu中有一个MenuItem,我想要在ContextMenu的上下文(放置目标)上触发命令:
<MenuItem Header="View" 
          ToolTip="Open the Member Central view for this member"
          Command="{x:Static local:Commands.CustomerViewed}" 
          CommandParameter="{Binding Path=PlacementTarget.DataContext, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" 
          CommandTarget="{Binding Path=PlacementTarget, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"
/>
    

要回复问题请先登录注册