title: WPF ChromiumWebBrowser the best way to open and close development tools
body: <p>I have standard WPF application that uses ChromiumWebBrowser CefSharp.Wpf.dll 49.0.0.0. <strong>Upgrade of the version to the latest one will be the real nightmare</strong>, hence I cannot consider it as an option.
  I have a small bug with opening and closing development tools:</p>
  
  <p>I open my dev tools through Command Binding:</p>
  
  <pre><code>&lt;FrameworkElement.Resources&gt;
      &lt;views:FreezableProxyClass x:Key="ProxyElement"
                                 ProxiedDataContext="{Binding Source={x:Reference This}, Path=DataContext}" /&gt;
  &lt;/FrameworkElement.Resources&gt;
  &lt;FrameworkElement.ContextMenu&gt;
      &lt;ContextMenu&gt;
          &lt;MenuItem Command="{Binding OpenDevToolsCommand}"
                    Header="Open Chrome Dev Tools"&gt;
              &lt;MenuItem.Icon&gt;
                  &lt;Image Source="../../Images/dev_tools_20x20.png"
                         Width="20"
                         Height="20" /&gt;
              &lt;/MenuItem.Icon&gt;
          &lt;/MenuItem&gt;
      &lt;/ContextMenu&gt;
  &lt;/FrameworkElement.ContextMenu&gt;
  
  &lt;FrameworkElement.InputBindings&gt;
      &lt;KeyBinding Key="F12"
                  Command="{Binding Source={StaticResource ProxyElement}, 
              Path=ProxiedDataContext.OpenDevToolsCommand}" /&gt;
  
  &lt;/FrameworkElement.InputBindings&gt;
  &lt;browser:WebBrowserEx BrowserContainer="{Binding}" /&gt;
  </code></pre>
  
  <p>Command handler code:</p>
  
  <pre><code>  private void OpenDevToolsCommandHandler()
      {
          if (Browser.IsBrowserInitialized)
          {
              Browser.ForceShowingDevTools = !Browser.ForceShowingDevTools;
          }
          else
          {
              MessageBox.Show("Wait till the full browser initialization", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
          }
      }
  </code></pre>
  
  <p>And extended web browser code has <code>ForceShowingDevTools</code> dependency property:</p>
  
  <pre><code> public bool ForceShowingDevTools
      {
          get { return (bool)GetValue(ForceShowingDevToolsProperty); }
          set { SetValue(ForceShowingDevToolsProperty, value); }
      }
  
      // Using a DependencyProperty as the backing store for ForceShowingDevTools.  This enables animation, styling, binding, etc...
      public static readonly DependencyProperty ForceShowingDevToolsProperty =
          DependencyProperty.Register("ForceShowingDevTools", typeof(bool), typeof(WebBrowserEx), new PropertyMetadata(false,
              (o, e) =&gt;
              {
                  WebBrowserEx browserEx = o as WebBrowserEx;
                  if (browserEx != null)
                  {
                      if ((bool)e.NewValue)
                      {
                          browserEx.ShowDevTools();
                      }
                      else
                      {
                          browserEx.CloseDevTools();
                      }
  
                  }
              }));
  </code></pre>
  
  <p>Whereas <code>ShowDevTools</code> and <code>CloseDevTools</code> are taken from original <code>WebBrowserExtensions</code> class.</p>
  
  <p>It works fine when I open and close my dev tools only through context menu or F12 key binding, but my code doesn't recognize when I close dev tools by "close window" button in right top corner of dev tools window:</p>
  
  <p><a href="https://i.stack.imgur.com/et9Wf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/et9Wf.png" alt="enter image description here"></a></p>
  
  <p>this closing doesn't inform my property, and consequently when next command invokes that handler, my application thinks that browser is opened and tries to close it. Hence <strong>I need to call my command twice to open dev tools</strong> if it was previously closed not through my command binding (from "X" button).</p>
  
  <p>Is there alternative option to open and close dev tools?</p>