Benjamin
Benjamin

Reputation: 129

Silverlight AutoCompleteBox on custom search

I have this object :

public class Person
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string FullName
    {
        get { return string.Format("{0} {1}", FirstName, LastName); }
    }

    public override string ToString()
    {
        return "Person " + LastName;
    }
}

And this Collecion:

public ICollection<Person> Persons { get; set; }

My AutoCompleteBox is :

<sdk:AutoCompleteBox ItemsSource="{Binding Persons}" FilterMode="Contains"
                                    SelectedItem="{Binding EmployeeSelected,Mode=TwoWay}"
                                 MinimumPrefixLength="2"/>

When i search in the Persons collection i want search by FirstName? Which is the property in AutoCompleteBox for say search by FirstName?

Upvotes: 0

Views: 701

Answers (1)

Anatolii Gabuza
Anatolii Gabuza

Reputation: 6260

Use ValueMemberPath :

<sdk:AutoCompleteBox ItemsSource="{Binding Persons}" FilterMode="Contains"
                                 SelectedItem="{Binding EmployeeSelected,Mode=TwoWay}"
                                 MinimumPrefixLength="2"
                                 ValueMemberPath="FirstName"/>

Upvotes: 1

Related Questions