wpf ListBoxItem資源 按鈕Button 綁定自身。將 ListBoxItem 當前的selectitem 作爲buttom 的參數傳遞

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

      
        }

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章