silverlight将单个棱镜命令委托添加到xaml中的项目列表
我正在使用 Prism 构建一个菜单(使用带有层次结构数据模板的 trtelerik 树视图,但希望细节并不重要),并且我正在尝试在每个菜单项绑定上设置一个 Click.Command,这些绑定都将调用相同的命令视图模型中定义的委托命令。菜单是由我不想在其中放置任何命令引用的项目组成的。
如何将命令绑定到 xaml 中的每个项目?我环顾四周,看起来在 WPF 中我可以使用相对源绑定并查找祖先,但在 silverlight 中似乎没有办法做到这一点。我可以以某种方式将委托设置为静态资源吗?我认为我无法为视图模型创建静态资源,因为它使用 Unity 来解析其构造函数的参数。
I'm building a menu using Prism (using a trtelerik tree view with hierarchy data templates but hopefully the details don't matter) and I'm trying to set up a Click.Command on each menu items bindings that will all call the same delegate command which is defined in the view model. The menu is built up out of items which I don't really want to put any references to the command in.
How do I bind the command to each of these items in xaml? I've looked around and it looks like in WPF I could use a relative source binding and find ancestors but there doesn't seem to be a way of doing this in silverlight. Can I setup the delegate as a static resource somehow? I don't think I can create a static resource to the view model as this uses Unity to resolve paramters to it's constructor.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种选择是通过 ElementName 绑定绑定到 UserControl 的 DataContext(或任何其他控件的 DataContext)。
这是一篇类似的帖子。
One option is to bind to the UserControl's DataContext (or any other control's DataContext) via ElementName binding.
Here's a similar post.