【发布时间】:2011-09-17 02:36:35
【问题描述】:
我有 ViewModel,它有一个 ObservableCollection[Employee] EmpCol,现在 ViewModel 与我的 View 绑定,并且 EmpCol 设置为与自定义控件的 ItemSource 一样。该自定义控件生成带有网格的堆栈面板,如果 EmpCol 中有 4 个对象,则其中将有 4 个带有网格的堆栈面板。现在在这些网格中,我有一列按钮。 现在我的问题是我无法将数据网格中该按钮的命令绑定到 Employee 类中的 RelayCommand。
我正在使用 MVVM 轻量级工具包,我找到了一种方法,实际上可以为这样的绑定命令提供完整路径
<Button x:Name="myButton" Width="20" Height="15" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<cmd:EventToCommand Command="{Binding Source={StaticResource VMLocator}, Path=MyVM.Employee.MyButtonCommand}" PassEventArgsToCommand="False"/> </i:EventTrigger>
</i:Interaction.Triggers>
</Button>
现在上述方法有效,但在我的情况下,我没有 Employee ,而是 Employee 集合,所以当我给出这样的绑定路径时 Path=MyVM.EmpCol.MyButtonCommand
它不起作用。我搜索了很多,但找不到任何解决方案。 因此,我们将不胜感激任何帮助来解决我的问题。
谢谢, 特立独行
命令绑定发生在 DataGrid 的一行内。
【问题讨论】:
标签: silverlight mvvm binding command mvvm-light