[英]DataGrid ItemsSource isn't displayed
I hope someone can tell me the reason for this behaviour: 我希望有人可以告诉我这种行为的原因:
If I do the following: 如果我执行以下操作:
<DataGrid ItemsSource="{Binding Model.Bytes}" .../>
My ViewModel constructor: 我的ViewModel构造函数:
public ViewModel()
{
Model = new Message();
Model.Bytes.Add(new Byte(){Range = "42"});
}
Nothing happens and the output window doesn't show any errors. 什么也没有发生,并且输出窗口没有显示任何错误。
But If I wrap this Byte collection: 但是如果我包装这个Byte集合:
public ICollection<Byte> Bytes
{
get { return Model.Bytes; }
set
{
Model.Bytes = value;
RaisePropertyChanged(()=> Bytes);
}
}
And write: 和写:
<DataGrid ItemsSource="{Binding Bytes}".../>
The datagrid shows the entry and I can add new ones. 数据网格显示该条目,我可以添加新条目。
My Message-Class 我的留言班
public Message()
{
Bytes = new ObservableCollection<Byte>();
}
public virtual ICollection<Byte> Bytes
{
get { return GetValue(() => Bytes); }
set { SetValue(() => Bytes, value); }
}
I think it is a notification problem, but I don't know where or why... 我认为这是一个通知问题,但我不知道在哪里或为什么...
Thank you in advance 先感谢您
<DataGrid ItemsSource="{Binding Model.Bytes}" .../>
this means your DataContext have to be an object with a PUBLIC property MODEL, and the type of this property must have a PUBLIC property Bytes. 这意味着您的DataContext必须是具有PUBLIC属性MODEL的对象,并且此属性的类型必须具有PUBLIC属性Bytes。 if this is the case, then it just seems to be a notification problem.
如果是这种情况,那么这似乎只是一个通知问题。
simply check your DataContext and Binding at runtime with Snoop. 只需在运行时使用Snoop检查您的DataContext和Binding。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.