Ravuthasamy
Ravuthasamy

Reputation: 599

Can you please explain why the Binding not working for DisplayMemberPath of ItemsControl?

Can any one please explain why the Binding is not working for DisplaymemberPath of ItemsControl?

And I checked with Reflector DisplayMemberPath of ItemsControl is only Dependency Property,and also Bindable attribute set True only.

XAML:

  <ComboBox x:Name="display" DisplayMemberPath="{Binding NewAddress.TelePhone}" ItemsSource="{Binding Persons}"/>

Person Class:

public class Person
{
    public Person()
    {
        persons = new ObservableCollection<NewAddress>();
        persons.Add(new NewAddress() { TelePhone = "MyNo" });
        persons.Add(new NewAddress() { TelePhone = "MyNo1" });
        persons.Add(new NewAddress() { TelePhone = "MyNo2" });
        persons.Add(new NewAddress() { TelePhone = "MyNo3" });
    }

    private ObservableCollection<NewAddress> persons;

    public ObservableCollection<NewAddress> Persons
    {
        get { return persons; }
        set { persons = value; }
    }

}

Address Class:

 public class NewAddress
{
    public string  TelePhone { get; set; }
}

Upvotes: 1

Views: 639

Answers (1)

Andrew
Andrew

Reputation: 835

DisplayMemberPath is the actual name of the property, not a binding to the property. Change your XAML code to the following:

<ComboBox x:Name="display" DisplayMemberPath="TelePhone" ItemsSource="{Binding Persons}"/>

Upvotes: 4

Related Questions