Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AutoSuggestBox query selected textbox

Tags:

c#

mvvm

xaml

uwp

I am using an AutoSuggestBox control to display some results, as such:

                <AutoSuggestBox Width="192"
                                PlaceholderText="Search"
                                HorizontalAlignment="Right"
                                ItemsSource="{Binding SearchResults}">
                    <i:Interaction.Behaviors>
                        ...
                    </i:Interaction.Behaviors>
                    <AutoSuggestBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock>
                                <Run Text="{Binding Name}" />
                                <Run Text="(" /><Run Text="{Binding Origin_Country[0]}" /><Run Text=")" />
                            </TextBlock>
                        </DataTemplate>
                    </AutoSuggestBox.ItemTemplate>

SearchResults (ItemsSource binding) is defined as such:

    private ObservableCollection<ShowModel> _searchResults = default(ObservableCollection<ShowModel>);
    public ObservableCollection<ShowModel> SearchResults { get { return _searchResults; } set { Set(ref _searchResults, value); } }

And ShowModel is a basic model with bindable properties.

The problem I'm having is when I'm clicking on one of the results, it is filling the textbox with the path of the model, as seen below:

Before selecting an entry:

After selecting an entry: enter image description here

What I want is to define some sort of template for the textbox to bind to one of the model's properties so the model path is not displayed. Is this even possible?

like image 443
kkyr Avatar asked Aug 16 '15 21:08

kkyr


1 Answers

Set TextMemberPath property to one of model's properties that you want to display.

TextMemberPath="someproperty"
like image 166
tao Avatar answered Sep 19 '22 22:09

tao