title: Silverlight searcher
body: <p>I'm trying to do something similar to a searcher in Windows Phone 7, and what I've done is the following, I've got a TextBox with a TextChanged event and a Listbox of HyperlinkButtons. What I try it's this:</p>
  
  <pre><code>private void searchFriend_TextChanged(object sender, TextChangedEventArgs e)
  {
    int index = 0;
    foreach (Person person in lbFriends.Items)
    {
      ListBoxItem lbi = lbFriends.ItemContainerGenerator.ContainerFromItem(index) as ListBoxItem;
      lbi.Visibility = Visibility.Visible;
  
      if (!person.fullName.Contains((sender as TextBox).Text))
      {
        lbi.Background = new SolidColorBrush(Colors.Black);
      }
      index++;
    }
  }
  </code></pre>
  
  <p>And here is the xaml:</p>
  
  <pre><code>&lt;TextBox x:Name="searchFriend" TextChanged="searchFriend_TextChanged" /&gt;
  &lt;ListBox x:Name="lbFriends" Height="535" Margin="0,0,0,20"&gt;
    &lt;ListBox.ItemTemplate&gt;
      &lt;DataTemplate&gt;
        &lt;StackPanel&gt;
          &lt;HyperlinkButton x:Name="{Binding id}" Content="{Binding fullName}" FontSize="24" Click="NavigateToFriend_Click" /&gt;
        &lt;/StackPanel&gt;
      &lt;/DataTemplate&gt;
    &lt;/ListBox.ItemTemplate&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p>The problem here is when I've 68 or more elements, the ContainerFromItem just returns null ListBoxItems...</p>
  
  <p>Any idea?</p>
  
  <p>Thank you all</p>