【发布时间】:2011-11-28 02:11:57
【问题描述】:
我将从我的代码的精简/净化版本开始:
型号:
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 列表已初始化但为空,那么当某些内容尝试绑定到(例如)列表中的第一个元素时,预期的行为是什么?我的理解是它只是忽略了绑定;这是真的吗?
【问题讨论】:
标签: silverlight data-binding datacontext