title: Creating a search box using WPF
body: <p>I'm trying to create a search box with the controls <code>TextBox</code> and <code>ListBox</code>.
  When I'm on the <code>TextBox</code> starting to type an event handler <code>GotFocus</code> open the <code>ListBox</code>.
  I want the <code>ListBox</code> to be closed when the <code>TextBox</code> not on focus. I tried to use the <code>LostFocus</code> event in the <code>TextBox</code>, but it didn't work.</p>
  
  <p>In which event handler should I use? I didn't find a good example implements this mechanism.</p>
  
  <p>Edit:
  I have something like that:</p>
  
  <pre><code>&lt;Canvas Name="m_MainCanvas" Grid.ColumnSpan="2" &gt;
  &lt;Rectangle MouseDown="Canvas_MouseDown" Fill="White" Height="280" HorizontalAlignment="Left" Margin="256,12,0,0" x:Name="m_MainRectangle" RadiusX="0" RadiusY="0" Stroke="Black" StrokeThickness="3" VerticalAlignment="Top" Width="238" /&gt;
  &lt;TextBox Height="23" Margin="10,0,0,210" Name="m_SearchTextBox" VerticalAlignment="Bottom" BorderThickness="0.5" BorderBrush="#69000000" TextChanged="m_SearchTextBox_TextChanged" FontFamily="Kristen ITC" Text="" FontSize="14" FontWeight="Black" HorizontalAlignment="Left" Width="165" Canvas.Top="86" Canvas.Left="274" LostFocus="m_SearchTextBox_LostFocus"/&gt;
  &lt;ListBox  ItemTemplate="{DynamicResource ListBoxItemDataTemplate}" ItemsSource="{Binding}" Name="m_FriendsSearchList" Visibility="Hidden" Background="#FFBCEB85"  Width="181" Height="193"  Canvas.Left="283" Canvas.Top="118"&gt;
      &lt;ListBox.ItemContainerStyle&gt;
          &lt;Style TargetType="{x:Type ListBoxItem}"&gt;
              &lt;EventSetter Event="MouseDoubleClick" Handler="HandleDoubleClickItemToSelect" /&gt;
          &lt;/Style&gt;
      &lt;/ListBox.ItemContainerStyle&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p></p>
  
  <p>The <code>MouseDown</code> event in the <code>Rectangle</code> control is used to get the <code>TextBox</code> out of focus, but it isn't working.</p>