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.
精彩评论