title: wpf LostFocus event of Textbox
body: <p>This is my xaml structure</p>
  
  <pre><code>&lt;StackPanel&gt;
    &lt;m:TextBoxWithEllipsis IsEllipsisEnabled="True"
       Name="A"
       LostFocus="text_LostFocus"/&gt;
    &lt;m:TextBoxWithEllipsis IsEllipsisEnabled="True"
       Name="B"
       LostFocus="text_LostFocus"/&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p><strong>=> This structure can loop more. Such as:</strong></p>
  
  <pre><code>&lt;StackPanel&gt;
    &lt;m:TextBoxWithEllipsis IsEllipsisEnabled="True"
       Name="A"
       LostFocus="text_LostFocus"/&gt;
    &lt;m:TextBoxWithEllipsis IsEllipsisEnabled="True"
       Name="B"
       LostFocus="text_LostFocus"/&gt;
  &lt;/StackPanel&gt;
  &lt;StackPanel&gt;
    &lt;m:TextBoxWithEllipsis IsEllipsisEnabled="True"
       Name="A"
       LostFocus="text_LostFocus"/&gt;
    &lt;m:TextBoxWithEllipsis IsEllipsisEnabled="True"
       Name="B"
       LostFocus="text_LostFocus"/&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p><strong>In .cs file, I define event lost focus as below</strong></p>
  
  <pre><code>private void text_LostFocus(object sender, RoutedEventArgs e)
  {
     TextBox textbox = ((TextBox)sender);
     if (textbox.Text.Trim().Length == 0)
     {
        System.Windows.Forms.DialogResult result1 = System.Windows.Forms.MessageBox.Show("Empty string!", "Warning",
                   System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
                  textbox.Dispatcher.BeginInvoke((Action)(() =&gt; { textbox.Focus(); }));
         return;
      }
      textbox.ScrollToHome();
  }
  </code></pre>
  
  <p><strong>The problem</strong>: If there are >= 2 textbox having value is empty ("").</p>
  
  <ol>
  <li>I click first empty textbox => I don't enter any characters.</li>
  <li>Then I click second empty textbox.</li>
  </ol>
  
  <p>==> Program always show the message box => If I click OK button, It show another. It occur forever. I can't close the program.</p>
  
  <p><strong>Question</strong>: <strong>If I have >= 2 empty textbox and I do same as problem above. How can I change the function <code>text_LostFocus</code> to solve the problem???</strong></p>
  
  <p><strong>DEFAULT</strong>:</p>
  
  <ul>
  <li><p>Value of these textbox is always empty (<strong>DEFAULT</strong>)</p></li>
  <li><p>Must use BeginInvoke => Because I want when user click to texbox, user must enter least a character.</p></li>
  </ul>