默认创建网格应用程序中会有DefaultViewModel属性其实现IObservableMap接口;
DataContext会绑定到其DefaultViewModel属性上;
我尝试着跳过DefaultViewModel直接把数据绑定到DataContext上也可以正常运行,请问默认生成的DataContext绑定到DefaultViewModel上的好处是什么?
如何更好的使用DefaultViewModel属性?
Hi,
DefaultViewModel实际上是LayoutAwarePage模板里自带的一个用来存储数据的类。这个类实际上是方便了数据绑定,当然你也可以替换你自己的,通过将数据添加到DefaultViewModel中在整个页面中进行数据绑定,这里有一篇Bob的文章里面有一段详细的介绍了LayoutAwarePage和DefaultViewModel:
https://skydrive.live.com/redir?resid=AF599C8D7F814B07!245
Aaron MSDN Community Support | Feedback to us Develop and promote your apps in Windows Store Please remember to mark the replies as answers if they help and unmark them if they provide no help.
感谢Aaron Xue,看过文章后理解更深刻了