silverlight将单个棱镜命令委托添加到xaml中的项目列表

发布于 2024-08-29 23:52:30 字数 303 浏览 1 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北城半夏 2024-09-05 23:52:30

一种选择是通过 ElementName 绑定绑定到 UserControl 的 DataContext(或任何其他控件的 DataContext)。

<UserControl x:Name="Control" xmlns:Cal="clr-namespace:Microsoft.Practices.Composite.Presentation.Commands;assembly=Microsoft.Practices.Composite.Presentation"...

Cal:Click.Command="{Binding ElementName=Control, Path=DataContext.SomeVMCommand}"

这是一篇类似的帖子。

One option is to bind to the UserControl's DataContext (or any other control's DataContext) via ElementName binding.

<UserControl x:Name="Control" xmlns:Cal="clr-namespace:Microsoft.Practices.Composite.Presentation.Commands;assembly=Microsoft.Practices.Composite.Presentation"...

Cal:Click.Command="{Binding ElementName=Control, Path=DataContext.SomeVMCommand}"

Here's a similar post.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文