<DataGridTemplateColumn Width="191" Header=" 操作">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Button Margin="8,0,0,0" Width="64" Height="32" Content="修改" Style="{StaticResource EditDelButtonstyle}" Command="{Binding DataContext.ModifyCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" Name="btnModify" ></Button>
<Button Margin="16,0,0,0" Width="64" Height="32" Content="删除" Style="{StaticResource EditDelButtonstyle}" Name="btnDel" Command="{Binding DataContext.DelCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}"></Button>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
绑定代码:
Command="{Binding DataContext.ModifyCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}"
ModifyCommand:绑定的命令名称
FindAncestor:寻找父级控件
AncestorType:父级控件类型