Windows Phone Toolkit AutoCompleteBox binding

1.1k Views Asked by At

I need to bind data to the dropdown options of the AutoCompleteBox control in the Windows Phone Toolkit.

This is the class. I create an array of the objects of this class and the autocompletebox's itemsource is this array of this class -

public class MyClass
{
    public string Name { get; set; }
    public string Value { get; set; }
}

Now, I was able to show the "Name" in the dropdown list of the autocompletebox, but here is the problem-

When I select a value ("Name") from the dropdown list, the text of the autocompletebox changes to something like -

"Classes.MyClass"

Instead of the value I selected, for example - I select "Jhon", in he selection changed event of the dropdown list I get the selected Object and I can get the "Name" property from it. but I need the text in the autocomplete box to be "Jhon". how to do that??

EDIT:-

Here is the xaml

<toolkit:AutoCompleteBox Name="SearchText" Grid.Row="1" BorderBrush="DarkGray" Background="LightGray" Foreground="Gray" FilterMode="None" MinimumPrefixLength="0" KeyDown="SearchText_KeyDown" TextChanged="ACBSearchText_TextChanged" Loaded="SearchText_Loaded" SelectionChanged="ACBSearchText_SelectionChanged">
                    <toolkit:AutoCompleteBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}" Foreground="Black"/>
                        </DataTemplate>
                    </toolkit:AutoCompleteBox.ItemTemplate>
                </toolkit:AutoCompleteBox>
1

There are 1 best solutions below

1
On BEST ANSWER

You need to put the ValueMemberBinding in your AutoCompleteBox

<toolkit:AutoCompleteBox Name="SearchText" ValueMemberBinding="{Binding Name}"/>