Displays the results of the re-filter SL4 AutoCompleteBox

I have a problem with AutoCompleteBox filtering.

It seems to repeat the previous filter.

For example, I type "A" and returns 1 element. I delete “A” and type “Z”, which should return 1 element.

The problem is that it returns the results from the filter “A” plus “Z”, I delete “Z” and press “S”, which returns 2 elements, and now it 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:AutoCompleteBox.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;
};
+5
source share
2 answers

, , , ? , ? , . - ListBox. , .

+2

AutoCompleteBox, .

var listBox = this.GetTemplateChild("Selector") as ListBox; 
var items = listBox.ItemsSource; 
listBox.ItemsSource = null; 
listBox.ItemsSource = items;

, , , , .

+1

All Articles