title: Hide/Display XAML elements or block LostFocus event
body: <p>I have a page containing two StackPanels, each containing one TextBox and one Button:</p>
  
  <pre><code>&lt;StackPanel x:Name="Row1"&gt;
  &lt;TextBox x:Name="TextBox1" Text="" GotFocus="OnFocusHandler" LostFocus="OffFocusHandler"/&gt;
  &lt;Button x:Name="Button1" Content="Convert" Click="OnClickHandler" Visibility="Collapsed"/&gt;
  &lt;/StackPanel&gt;
  
  &lt;StackPanel x:Name="Row2"&gt;
  &lt;TextBox x:Name="TextBox2" Text="" GotFocus="OnFocusHandler" LostFocus="OffFocusHandler"/&gt;
  &lt;Button x:Name="Button2" Content="Convert" Click="OnClickHandler" Visibility="Collapsed"/&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p>I would like to do the following:</p>
  
  <ul>
  <li>When a textbox has focus, the other textbox must be hidden and the corresponding button must show</li>
  <li>When a textbox is out of focus, we are back to the original display: only empty textboxes are visible </li>
  <li>I don't want the button to be able to trigger the OffFocusHandler</li>
  </ul>
  
  <p>This is the current code that I have for the three handlers:</p>
  
  <pre><code>private void OnFocusHandler(object sender, RoutedEventArgs e)
  {
      TextBox SenderTextBox = (TextBox)sender;
  
      if (SenderPanel.Name == "TextBox1")
      {
          Button1.Visibility = Visibility.Visible;
      }
      else if (SenderPanel.Name == "TextBox2")
      {
          Button2.Visibility = Visibility.Visible;
      }
  }
  
  private void OffFocusHandler(object sender, RoutedEventArgs e)
  {
      TextBox1.Text = "";
      TextBox2.Text = "";
      Button1.Visibility = Visibility.Collapsed;
      Button2.Visibility = Visibility.Collapsed;
  }
  
  private void OnClickHandler(object sender, RoutedEventArgs e)
  {
      // some stuff unrelated to my issue
  }
  </code></pre>
  
  <p>How do I avoid the button clicking to trigger the <code>OffFocusHandler</code> code?
  Is there another way to code this? I'm a complete beginner so I may not think the right way.</p>