简体   繁体   中英

Windows Phone Toolkit AutoCompleteBox binding

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>

您需要将ValueMemberBinding放入AutoCompleteBox中

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM