title: WPF XAML Grid- KeyBinding doesn't seem to work
body: <p>I am trying to add the functionality to allow the user to 'zoom in' on a web page displayed in a <code>ChromiumWebBrowser</code> on the GUI of my WPF application, by using the keyboard.</p>
  
  <p>I have the following function in the code-behind for my XAML:</p>
  
  <pre><code>private void zoomInExecuted(object sender, ExecutedRoutedEventArgs e)
      {
          Console.WriteLine("'zoomInExecuted() called. ");
          browser.ZoomLevel++;
      } 
  </code></pre>
  
  <p>To enable this function to be called, I have added the following <code>&lt;Grid.InputBindings&gt;</code> tags to the <code>&lt;Grid&gt;</code> that I'm using to display the <code>ChromiumWebBrowser</code>:</p>
  
  <pre><code> &lt;Grid x:Name="grdBrowserHost" MinHeight="900" Height="Auto" MinWidth="1205" Width="Auto" Margin="5,0,0,0" DockPanel.Dock="Bottom" Grid.ColumnSpan="1" &gt;
      &lt;Grid.InputBindings&gt;
          &lt;KeyBinding Key="Add" Command="{Binding Path=zoomInExecuted}"&gt;&lt;/KeyBinding&gt;
       &lt;/Grid.InputBindings&gt;
      ...
  &lt;/Grid&gt;
  </code></pre>
  
  <p>As I understand, this should mean that the <code>zoomInExecuted(...)</code> function should be called when the <code>+</code> button is pressed on the keyboard, when the Grid displaying the browser has focus.</p>
  
  <p>But, when I run my application, and click inside the browser to ensure it has focus, if I then press '+' on the keyboard, nothing happens, and I'm not even seeing the debug from my <code>zoomInExecuted()</code> function in the console, so it seems that pressing the '+' key is not actually calling that function. Have I done the <code>KeyBinding</code> correctly? Is there something I'm missing from my code here?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I have tried using an <code>ICommand</code>, as suggested in the answers:</p>
  
  <pre><code>public ICommand zoomInCommand
      {
          get
          {
              _zoomIn = new DelegateCommand(zoomInExecuted()); //CallZoomIn());
              return zoomIn;
          }
      }
  </code></pre>
  
  <p>and calling this in the <code>KeyBinding</code> in the XAML:</p>
  
  <pre><code>&lt;KeyBinding Key="Add" Command="{Binding Path=zoomInCommand}"&gt;&lt;/KeyBinding&gt;
  </code></pre>
  
  <p>but I'm getting a compile error in the C# which says:</p>
  
  <blockquote>
    <p>The type or namespace name 'DelegateCommand' could not be found (are you missing a using directive or an assembly reference?)</p>
  </blockquote>
  
  <p>Do I need to add a particular reference or <code>using</code> statement in order to be able to use this?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I have also tried adding the <code>&lt;KeyBinding ...&gt;</code> tags to both the <code>&lt;Grid&gt;</code> that's holding the browser object, and the browser itself in the XAML, i.e.</p>
  
  <pre><code>&lt;Grid x:Name="grdBrowserHost" MinHeight="900" Height="Auto" MinWidth="1205" Width="Auto" Margin="5,0,0,0" DockPanel.Dock="Bottom" Grid.ColumnSpan="1" &gt;
      &lt;Grid.InputBindings&gt;
          &lt;KeyBinding Modifiers="Ctrl" Key="Add" Command="{Binding zoomInExecuted}"&gt;&lt;/KeyBinding&gt;
      &lt;/Grid.InputBindings&gt;
      ...
      &lt;cefSharp:ChromiumWebBrowser Name="browser" Height="Auto" Width="Auto" Grid.Row="0" Address="https://web.riviam.com" Margin="25,35,-0.2,0" &gt;
          &lt;cefSharp:ChromiumWebBrowser.InputBindings&gt;
              &lt;KeyBinding Modifiers="Ctrl" Key="Add" Command="{Binding zoomInExecuted}"&gt;&lt;/KeyBinding&gt;
          &lt;/cefSharp:ChromiumWebBrowser.InputBindings&gt;
      &lt;/cefSharp:ChromiumWebBrowser&gt;
  </code></pre>
  
  <p>But the <code>zoomInExecuted(...)</code> function never appears to be called (I never see the debug from this function displayed in the console)- it seems that pressing <code>CTRL+</code> on the keyboard is never registered by the application...</p>
  
  <p>Is there an <code>EventHandler</code>/ <code>KeyboardListener</code> or something similar that I need to add to the application?</p>