开发者

silverlight adding single prism command delegate to a list of items in xaml

开发者 https://www.devze.com 2022-12-27 18:05 出处:网络
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 bindin

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号