Silverlight 3.0:如何将 DataGridColumn 绑定到 ICommand,其中 DataGrid 绑定到 ItemsSource
我有一个绑定到集合的 SL3 DataGrid。数据网格的一列是 HyperlinkButton 列,我想将该列的单击事件绑定到虚拟机中存在的 ICommand。
伪代码:
DataGrid ItemsSource="{Binding someCollection}" DataGridHyperLinkColumn Commands.Command="{Binding myClickCommand}"
现在,在这种情况下,Commands.Command 尝试在 someCollection 中查找 myClickCommand,而不是从 VM myClickCommand 属性获取它。
我还尝试修复 Commands.Command="{Binding Path=DataContext.myClickCommand, ElementName=nameOfUserControl}" 但也失败了。
出路是什么?...我不想使用 BindingHelper 因为 SL3 已经支持 ElementBinding...
I have a SL3 DataGrid bound to a collection. One column of the datagrid is a HyperlinkButton column and I want to bind the click event of the column to an ICommand present in the VM.
pseudo code:
DataGrid ItemsSource="{Binding someCollection}"
DataGridHyperLinkColumn Commands.Command="{Binding myClickCommand}"
Now in this scenario the Commands.Command is trying to locate the myClickCommand within the someCollection instead of getting it from the VM myClickCommand property.
I have also tried the fix Commands.Command="{Binding Path=DataContext.myClickCommand, ElementName=nameOfUserControl}" but that fails as well.
What is the way out...? I don't want to use BindingHelper since SL3 already supports ElementBinding...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
瞧...Dan Wahlin 已经提供了一个解决方案:http://weblogs.asp.net/dwahlin/archive/2009/08/20 /创建-silverlight-datacontext-proxy-to-simplify-data-binding-in-nested-controls.aspx
voila...there is a solution already available from Dan Wahlin out here: http://weblogs.asp.net/dwahlin/archive/2009/08/20/creating-a-silverlight-datacontext-proxy-to-simplify-data-binding-in-nested-controls.aspx