SL4 AutoCompleteBox repeating filter results issue
I'm having an issue with the AutoCompleteBox filtering.
It seems to be rembering the previous filter.
For example I type in 'A' and it returns 1 item. I delete the 'A' and type in 'Z' which should return 1 item.
The problem is it returns the results from the 'A' filter plus the 'Z', I delete 'Z' and type 'S' which brings back 2 items and it now displays the results from all 3 filters.
Am I doing something wrong?
stockTypes.Add(new StockTypeDTO() { Description = "Steel Coil", StockCode = "SC" });
stockTypes.Add(new StockTypeDTO() { Description = "Palletised Steel Coil", StockCode = "PS" });
stockTypes.Add(new StockTypeDTO() { Description = "ZZZZZ", StockCode = "ZZ" });
<input:AutoCompleteBox x:Name="testauto" FilterMode="Custom">
<input:AutoCompleteBo开发者_JS百科x.ItemTemplate>
<DataTemplate>
<StackPanel>
<ContentPresenter Content="{Binding Description}" />
</StackPanel>
</DataTemplate>
</input:AutoCompleteBox.ItemTemplate>
</input:AutoCompleteBox>
testauto.ItemsSource = this.StockTypes;
testauto.ItemFilter = (search, item) =>
{
StockTypeDTO stockType = item as StockTypeDTO;
if (stockType != null)
{
string filter = search.ToUpper(CultureInfo.InvariantCulture);
return (stockType.StockCode.ToUpper(CultureInfo.InvariantCulture).Contains(filter)
|| stockType.Description.ToUpper(CultureInfo.InvariantCulture).Contains(filter));
}
return false;
};
Also, the previous results are shown, but treated like they are non-existent right? I mean, selecting them don't change the autocompletebox's value? I'm having the same issue, got it after changing the style. In my situation it's because of ListBox's style. If you're using a custom style for listbox, try removing it & use the default style.
I ended up inheriting AutoCompleteBox capturing the Populated event and performing this hack.
var listBox = this.GetTemplateChild("Selector") as ListBox;
var items = listBox.ItemsSource;
listBox.ItemsSource = null;
listBox.ItemsSource = items;
It fixed the problem, I'm sure there's a cleaner way of doing it but I didn't have time to mess around with it.
精彩评论