任何人都可以解释为什么绑定不适用于 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; }
}