0

削除ボタンのあるデータグリッドがあります XAML は次のようになります。

<sdk:DataGridTemplateColumn Header="Del/Tgl" >
    <sdk:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <Button Content="Delete" 
           Command="{Binding DeleteRowCommand}"
                    CommandParameter="{Binding Column}"
                    />
        </DataTemplate>
    </sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>

John Papa のコードをコピーして、ICommand を DelegateCommand として実装しました。ViewModel にパブリック プロパティを追加しました。

public ICommand DeleteRowCommand {get;set;}

ビューモデルのコンストラクターで、次のコマンドを設定します。

this.DeleteRowCommand = new DelegateCommand(onDelete, CanDelete);

そして最後に 、onDelete、およびCanDelete:

private void onDelete(object param)
{
    // Get the Column Name
    string strColumnName = param as string ?? string.Empty;
}

private bool CanDelete(object param)
{
    // If we ae here we can delete the row
    return true;
}

Silvelight グリッドではすべてが機能しますが、削除ボタンをクリックするとonDelete機能しなくなります。私は何を間違っていますか?

4

1 に答える 1

1

Basically Command binding will look for DeleteRowCommand property inside the Object ( I mean the list of object that is binded as ItemSource to the datagrid). So you need to set the Source of Binding or use relativesource if you are using SL5.

Cheers! Vinod

于 2012-08-09T03:50:31.973 に答える