第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

綁定數(shù)據(jù)網(wǎng)格按鈕 mvvm

綁定數(shù)據(jù)網(wǎng)格按鈕 mvvm

C#
慕勒3428872 2023-08-20 15:40:47
我有數(shù)據(jù)網(wǎng)格,其中一列是按鈕列,我想將此單擊綁定到視圖模型,但它沒有到達視圖模型功能。<DataGrid  CanUserAddRows="False" AutoGenerateColumns="False"  ItemsSource="{Binding TableComments}" SelectedItem="{Binding SelectedRow}"     x:Name="dataGrid" >    <DataGrid.Columns >                           <DataGridTemplateColumn Header="Delete">            <DataGridTemplateColumn.CellTemplate>                 <DataTemplate>                    <Button Command="{Binding DeleteCommentCommand}" >Delete</Button>                 </DataTemplate>             </DataGridTemplateColumn.CellTemplate>         </DataGridTemplateColumn>   </DataGrid.Columns></DataGrid>在視圖模型中:public ICommand DeleteCommentCommand { get; private set; }public MyViewModel(){   DeleteCommentCommand = new RelayCommand(Delete);}void Delete(){}我感覺問題出在這一行: <Button Command="{Binding DeleteCommentCommand}" >Delete</Button>
查看完整描述

1 回答

?
qq_花開花謝_0

TA貢獻1835條經(jīng)驗 獲得超7個贊

DeleteCommentCommand綁定到 DataGrid item DataContext,而不是 DataGridDataContext本身(ViewModel)。您應該設(shè)置適當?shù)?DataContextCellTemplate或更新一點綁定,例如


Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}, Path=DataContext.DeleteCommentCommand}"

您還可以更新命令并將參數(shù)傳遞給RelayCommand方法Delete


public MyViewModel()

{

   DeleteCommentCommand = new RelayCommand(item => Delete(item));

}


void Delete(object item)

{

}

并在xaml中傳遞值CommandParameter="{Binding}"


查看完整回答
反對 回復 2023-08-20
  • 1 回答
  • 0 關(guān)注
  • 134 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號