Skip to main content

Microsoft Silverlight

Answered Question AutoComplete UI not reflecting ObservableCollection<T>.Clear() - Silverlight 3RSS Feed

(0)

Zack123
Zack123

Member

Member

4 points

4 Posts

AutoComplete UI not reflecting ObservableCollection<T>.Clear() - Silverlight 3

Hi,

I have an AutoComplete control that works great, other than the fact that the ObservableCollection<T>.Clear() method does not alter the ItemsSource.  So when I offset my filtering and searching to the server, the results just keep being added to the list.  Is there anything I can do to get around this?  I have also repproduced this is a simple test application.

 Any help is greatly appreciated.

 Zack

 

public partial class MainPage : UserControl

{

public MainPage()

{

InitializeComponent();

TestOBVC = new ObservableCollection<People>();

TestOBVC.Add(new People() { FirstName = "John", LastName = "Smith" });

TestOBVC.Add(new People() { FirstName = "John", LastName = "Smithe" });

TestOBVC.Add(new People() { FirstName = "John", LastName = "Smithers" });

TestOBVC.Add(new People() { FirstName = "John", LastName = "Schimdt" });

this.TestAutoSelector.ItemsSource = TestOBVC;

this.TestAutoSelector.ItemFilter = ((search, item) =>

{

People person = item as People;

if (person != null)

{

string filter = search.ToLower();

return (person.FirstName.ToLower().Contains(filter) ||

person.LastName.ToLower().Contains(filter));

}

return false;

 

});

}

private void Button_Click(object sender, RoutedEventArgs e)

{

TestOBVC.Clear();

}

public ObservableCollection<People> TestOBVC { get; set; }

public class People

{

public People()

{

}

public string FirstName { get; set; }

public string LastName { get; set; }

}

}

------------------------------------------And the Xaml -------------------------------------

<Grid x:Name="LayoutRoot" Background="White">

<Grid.RowDefinitions>

<RowDefinition Height="40" />

<RowDefinition Height="*" />

</Grid.RowDefinitions>

<Button Click="Button_Click" Content="Click me to to clear the autocomplete" Width="200" Height="30" VerticalAlignment="Top" Grid.Row="0"></Button>

<input:AutoCompleteBox Name="TestAutoSelector" Grid.Row="1" Width="200" Height="30">

<input:AutoCompleteBox.ItemTemplate>

<DataTemplate>

<StackPanel Orientation="Horizontal">

<TextBlock Text="{Binding Path=FirstName}"></TextBlock>

<TextBlock Text="{Binding Path=LastName}"></TextBlock>

</StackPanel>

</DataTemplate>

</input:AutoCompleteBox.ItemTemplate>

</input:AutoCompleteBox>

</Grid>

</UserControl>

 

 

 

 

bartczernicki
bartczer...

Contributor

Contributor

3838 points

666 Posts

Re: AutoComplete UI not reflecting ObservableCollection<T>.Clear() - Silverlight 3

 On the click event you can set the ItemSource to null and then back to the collection.

Please "Mark as Answer" if any of my content helped
Bart Czernicki
http://www.silverlighthack.com | http://www.twitter.com/bartczernicki

jwilcox
jwilcox

Participant

Participant

1082 points

187 Posts

Microsoft
Answered Question

Re: AutoComplete UI not reflecting ObservableCollection<T>.Clear() - Silverlight 3

We actually made some changes to the internal handling of the Reset collection notification event, so in the next Silverlight 3 SDK release (and Silverlight 2 Toolkit release) this should be fixed.

Jeff Wilcox [MSFT]
Silverlight
http://www.jeff.wilcox.name/blog/

This posting is provided "AS IS" with no warranties, and confers no rights.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities