0

ビューにボタンがあります:

<Button Grid.Row="0" Grid.Column="1" Content="Export to CSV "  
        HorizontalAlignment="Right" VerticalAlignment="Center"
        Margin="2,2,20,2" Style="{StaticResource ExportButton}"
        Command="{Binding ExportToExcelCommand}"
        CommandParameter="{TelerikGrid}"
/>

ExportCommand、私は自分のViewModelas を持っています:

private RelayCommand _exportToExcelCommand;
public ICommand ExportToExcelCommand
{
    get
    {
        if (_exportToExcelCommand == default(RelayCommand))
        {
            _exportToExcelCommand = new RelayCommand(ExportToExcel, CanExport);
        }
        return _exportToExcelCommand;
    }
}

private void ExportToExcel(Object param)
{
    try
    {
        //ToDo: Update With Command Parameters
        RadGridView gdv = new RadGridView();

        using (Stream stream = dialog.OpenFile())
        {
            gdv.Export(Columns);
        }
    }
    catch (FaultException ex)
    {
        var faultMessage = ex.Reason.GetMatchingTranslation().Text + "/n" + ex.StackTrace;
    }
}

今、私は RadGridView の新しいインスタンスを作成しています:

RadGridView gdv = new RadGridView();

しかし、代わりに、XAML からgdv渡された値から割り当てたいCommandParameter

4

1 に答える 1

3
RadGridView gdv = (RadGridView)param;

paramは送信したオブジェクトなので、元の場所にキャストするだけです。

于 2013-02-26T11:40:24.327 に答える