3
我會跟我的代碼精簡/消毒版本開始:Silverlight的數據綁定的DataContext行爲
型號:
class DataObj : INotifyPropertyChanged {
// these actually call OnPropertyChanged, and have associated private variables
public string Name { get; set; }
public int Age { get; set; }
}
class DataContextObj : INotifyPropertyChanged {
public List<DataObj> DataItems { get; set; }
}
查看:
<StackPanel x:Name="MyPanel">
<TextBlock Text="{Binding Path=DataItems[0].Name}" />
<TextBlock Text="{Binding Path=DataItems[0].Age}" />
</StackPanel>
查看代碼隱藏:
//in the constructor
MyPanel.DataContext = new DataContextObj();
現在,我的問題是,如果DataItems列表已初始化但爲空,當某些事情嘗試綁定到列表中的第一個元素時,預期的行爲是什麼?我的理解是,它只是忽略了約束力;真的嗎?
太好了,謝謝! –