我在datagrid的第一列有按钮.我正在使用MVVM并尝试在ViewModel中将Command绑定到Command,但是当我单击每行中的按钮时,它不起作用(它不会在ViewModel中调用Command)但是如果我将该按钮移出datagrid则它正常工作.
如何从MVVM中的datagrid中的按钮触发事件?
更新1:
XAML的代码是:
<datagrid:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal"
VerticalAlignment="Center">
<Button x:Name="button" Content="View" Margin="5" DataContext="{StaticResource XDataContext}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{Binding ViewOrganizationCommand}"
CommandParameter="{Binding ElementName=dtgOrganizations, Path=SelectedItem}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</StackPanel>
</DataTemplate>
</datagrid:DataGridTemplateColumn.CellTemplate>
Run Code Online (Sandbox Code Playgroud)
ViewModel的代码是:
public ViewModelCommand ViewOrganizationCommand { get; set; }
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8621 次 |
最近记录: |