注意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;
}