Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF ComamndBinding Help on MenuItem
    primarykey
    data
    text
    <p>New to WPF...was reading this <a href="https://stackoverflow.com/questions/3339257/wpf-routed-command-with-bindings-per-tab">WPF Routed Command with Bindings per-Tab</a> and am close to getting it working. </p> <p>The MenuItem is disabled until my RuleTab (tabitem) is selected but rather than pop my Find Dialog it shows System.Windows.Input.CommandBinding on the menu. What am I doing wrong?</p> <p>XAML:</p> <pre><code>&lt;MenuItem Header="_Find..." IsEnabled="{Binding ElementName=RuleTab, Path=IsSelected}" &gt; &lt;CommandBinding Command="Find" Executed="ExecuteFind" CanExecute="Find_CanExecute" &gt;&lt;/CommandBinding&gt; &lt;/MenuItem&gt; </code></pre> <p>Code-Behind:</p> <pre><code> 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; } </code></pre> <p>Any suggestions would be greatly appreciated!</p> <p>Figured it out! Thanks to those responded. All I had to do was move my commandbinding to:</p> <pre><code>&lt;Window.CommandBindings&gt; &lt;CommandBinding Command="Find" Executed="ExecuteFind" CanExecute="Find_CanExecute" &gt;&lt;/CommandBinding&gt; &lt;/Window.CommandBindings&gt; </code></pre> <p>Then reference Command=Find in my MenuItem.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload