注意Command里的属性AncestorType 所指向的是当前窗体(window)若是用户控件的话应该为(usercontroller),CommandParameter 所指向的是当前自身。
<Button Margin="5 0" Command="{Binding RelativeSource={RelativeSource AncestorType=Window},Path=DataContext.BtnCallReportCommand}"
CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}" Height="30" Style="{StaticResource BtnInfoStyle}" Width="50" Visibility="{Binding VisShowCallReport,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Content="取报告"></Button>
ViewModel中的方法接受参数为:
private void BtnCallReportExecute(object obj)
{
System.Windows.Controls.Button btn = obj as System.Windows.Controls.Button;
YTPatientInfo patientInfo = btn.DataContext as YTPatientInfo;
}