上干货
<DataGridTemplateColumn Header="操作" Width="1*"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <StackPanel Orientation="Horizontal" HorizontalAlignment="Center"> <Button Style="{StaticResource CcHotelButtonStyle}" Margin="2 0 2 0" Width="60" Height="30"
Command="{Binding DataContext.OprationQMUploadButtonCommand,UpdateSourceTrigger=PropertyChanged,
RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}">签名</Button> <Button Style="{StaticResource CcHotelButtonStyle}" Margin="2 0 2 0" Width="60" Height="30"
Command="{Binding DataContext.OprationLookFileButtonCommand,
RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}">查看</Button> </StackPanel> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn>
/// <summary> /// 签名 /// </summary> public RelayCommand<Window> OprationQMUploadButtonCommand { get; set; } /// <summary> /// 查看 /// </summary> public RelayCommand<Window> OprationLookFileButtonCommand { get; set; }
构造函数中标签:DataContext,OprationLookFileButtonCommand,RelayCommand,DataGrid,RelativeSource,按 From: https://www.cnblogs.com/Fengge518/p/16896176.html
OprationQMUploadButtonCommand = new RelayCommand<Window>((t) => OprationQMUploadButton(t)); OprationLookFileButtonCommand = new RelayCommand<Window>((t) => OprationLookFileButton(t));