任何人都可以解釋爲什麼綁定不能用於ItemsControl的DisplaymemberPath?你能解釋爲什麼綁定不能用於ItemsControl的DisplayMemberPath嗎?
而我用Reflector DisplayMemberPath檢查ItemsControl只是依賴屬性,而且Bindable屬性只設置True。
XAML:
<ComboBox x:Name="display" DisplayMemberPath="{Binding NewAddress.TelePhone}" ItemsSource="{Binding Persons}"/>
Person類:
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; }
}
發佈您的數據項目。 (我猜的人類),以及地址類 –
10如果您省略了DiplayMemberPath,您是否至少會獲得重複文本的行? – Paparazzi
請看我編輯的問題。 – Ravuthasamy