Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1770
DataPresenterExcelExporter with MVVM
posted

Is there a way to use the DataPresenterExcelExporter with MVVM? The export method requires an instance of an object that has DataPresenterBase as the base class. In my case I'm using a xamDataGrid. I'm also using the MVVM Light toolkit as a side note. Is there a way to pass the xamDataGrid object reference to my view model?

This is what you would do in the code behind:

 DataPresenterExcelExporter exporter = (DataPresenterExcelExporter)this.Resources["Exporter"]; 
exporter.Export(xamDataGridInstance, excelSheet);
  • 34810
    Verified Answer
    Offline posted

    Hello KrisVice,

    Thank you for your post!

    While I am not entirely familiar with the MVVM Light toolkit, the simplest way that I can think of to export your XamDataGrid to Excel in an MVVM fashion is through the usage of an ICommand. If you give the XamDataGrid a name and bind to it using an ElementName binding for the CommandParameter property of the element that you attach the command to, you can pass your instance of your XamDataGrid that way.

    I have attached an example where I hook an ICommand to a Button's Command property and pass the XamDataGrid to the command via the CommandParameter property on the button. Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer
    Infragistics Inc.
    www.infragistics.com/support

    XDGExportExcelMVVMCase.zip