title: Open Links containing pattern in different tab in CefSharp WPF
body: <p>I have an application with two tabs in a tab control, each containing a CefSharp ChromiumWebBrowser. Let's call these ChromiumWebBrowsers <code>searchBrowser</code> and <code>detailsBrowser</code>. </p>
  
  <p>Let's say I click a link in <code>searchBrowser</code>, and if that link contains the text "xrep2", I want the link to be opened in <code>detailsBrowser</code>, else it should be opened in <code>searchBrowser</code>.</p>
  
  <p>In a previous version of this application, I used the WinForms web browser control. I'm rewriting the app in WPF and using CefSharp. with the WinForms it was quite simple. In the <code>Navigating</code> event, you do something like</p>
  
  <pre><code>private void browser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
  {
      if (browser.StatusText.Contains("xrep2."))
      {
          e.Cancel = true;
          detailsBrowser.Url = new Uri(browser.StatusText);
          tabControl1.SelectedIndex = 1;
      }
  }
  </code></pre>
  
  <p>But when using CefSharp, it appears I have to create an event inside a LifeSpanHandler per <a href="https://stackoverflow.com/questions/30553577/how-to-handle-popup-links-in-cefsharp">this post</a> with an event that fires when a <code>target="_blank"</code> link is clicked. I'm not super comfortable creating and subscribing to custom events, so I'd like to find an easier way to do this, but if not, I need to figure out how to subscribe a method to the event created by <code>public event Action&lt;string&gt; PopupRequest;</code> and where to put the logic (something like <code>if(searchBrowser.Address.Contains("xrep2")) detailsBrowser.Address = X else searchBrowser.Address = X</code></p>
  
  <p>I have the LifeSpanHandler class code below, including the PopupRequest event that is supposed to fire when a <code>target="_blank"</code> link is clicked, but I'm stuck at this point.</p>
  
  <pre><code>public class LifeSpanHandler : ILifeSpanHandler
  {
      public event Action&lt;string&gt; PopupRequest;
  
      public virtual bool OnBeforePopup(IWebBrowser browserControl, string sourceUrl, string targetUrl, ref int x, ref int y, ref int width,
          ref int height)
      {
          if (PopupRequest != null)
              PopupRequest(targetUrl);
  
          return true;
      }
  }
  </code></pre>