【问题标题】:silverlight adding single prism command delegate to a list of items in xamlsilverlight 将单个 prism 命令委托添加到 xaml 中的项目列表
【发布时间】:2010-04-23 11:01:01
【问题描述】:

我正在使用 Prism 构建一个菜单(使用带有层次结构数据模板的 trtelerik 树视图,但希望细节无关紧要)并且我正在尝试在每个菜单项绑定上设置一个 Click.Command调用视图模型中定义的相同委托命令。菜单是由我不想在其中放置对命令的任何引用的项目组成的。

如何将命令绑定到 xaml 中的每个项目?我环顾四周,看起来在 WPF 中我可以使用相对源绑定并找到祖先,但在 silverlight 中似乎没有办法做到这一点。我可以以某种方式将委托设置为静态资源吗?我不认为我可以为视图模型创建静态资源,因为它使用 Unity 将参数解析为它的构造函数。

【问题讨论】:

    标签: silverlight mvvm prism


    【解决方案1】:

    一种选择是通过 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}"
    

    Here's a similar post.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-12
      • 1970-01-01
      相关资源
      最近更新 更多