在 Silverlight 3 DataGrid 中使用 Mode=TwoWay 和 AutogenerateColumns=True
我的 List
有一些公共属性,我想将它们绑定到 DataGrid 中的列。不幸的是,公共属性的名称不好,我什至可能直到运行时才知道它们是什么。因此,我设置了 AutoGenerateColumns=True 并拦截每个 DataGridAutoGenerateColumnEvent,以便我可以检查它是什么,然后取消它、隐藏它或将标题命名为其他名称。
它工作得很好,但我不知道如何设置 Mode=TwoWay ,以便在生成所有列并且有人编辑单元格后触发我的 INotifyPropertyChanged 事件。
奖金问题: 在上下导航网格的行时,网格的数据上下文是否会自动设置为该行的 BusinessObject?
My List<BusinessObject>
has some public properties that I want to bind to columns in a DataGrid. Unfortunately, the names of the public properties are not good and I may not even know what they are until runtime. For this reason, I set AutoGenerateColumns=True and interecept each DataGridAutoGeneratingColumnEvent so I can inspect what it is and either cancel it, hide it, or name the header something else.
It works great but I cannot figure out how to set the Mode=TwoWay so that my INotifyPropertyChanged events get fired once all the columns are generated and somebody edits a cell.
Bonus question:
On navigating up and down the rows of the grid, does the grid's datacontext automatically get set with that row's BusinessObject
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢这个< /a> post,我了解到绑定发生在 DataGridTextColumn 上。因此,在运行时设置模式的方法是:
现在我有了 TwoWay 绑定,我必须弄清楚更改如何使其返回到我的 BusinessObject。
Thanks to this post, I learned that the binding happens on DataGridTextColumn. So the way to set the Mode at runtime is:
Now that I have TwoWay binding, I have to figure out how changes make it back to my BusinessObject.
如果绑定正确,您的业务对象将自动接收所需的更新。要以编程方式进行绑定,您可能需要更多代码,例如:
If the binding is correct your business objects will automatically receive the required updates. To do you binding programmatically you might need a little more code, something like: