title: How to Search for a text in datagrid in WPF and highlight the searched text?
body: <p>I'm searching the text in data grid view in WPF(XAML) and trying to highlight the matching string. In turn I want add the additional functionality to replace the given entered word with a different word. Same as we do in word Document. </p>
  
  <p>I've tried this so far. </p>
  
  <pre><code>string SearchString = "";
  
  public string HighlightText(string InputTxt)
  {
      if (string.IsNullOrEmpty(SearchString))
      {
          return InputTxt;
      } 
      else 
      {
          Regex ResultStr = default(Regex);
          ResultStr = new Regex(SearchString.Replace(" ", "|"), RegexOptions.IgnoreCase);
          return ResultStr.Replace(InputTxt, new MatchEvaluator(ReplaceWords));
      }
  }
  
  public string ReplaceWords(Match m)
  {
      txtFindWord.SelectionStart = 0;
      txtFindWord.SelectionLength = txtFindWord.Text.Length;
  }
  </code></pre>