1

任何人都可以解释为什么绑定不适用于 ItemsControl 的 DisplaymemberPath 吗?

我检查了 ItemsControl 的 Reflector DisplayMemberPath 只是依赖属性,而且 Bindable 属性也只设置为 True。

XAML:

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

人物类:

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; }
    }

}

地址类:

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

1 回答 1

4

DisplayMemberPath 是属性的实际名称,而不是属性的绑定。将您的 XAML 代码更改为以下内容:

<ComboBox x:Name="display" DisplayMemberPath="TelePhone" ItemsSource="{Binding Persons}"/>
于 2013-08-07T18:08:07.597 回答