Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using WPF Infragistics Excel export functionality with MVVM

I'm using the Infragistics WPF datagrid and I want to make use of the Excel export functionality that Infragistics provides. The API for the Excel export requires an instance of the grid as a parameter. This isn't very MVVM friendly since I'd prefer to handle the command to export the data in my viewModel which wouldn't know about the instance of the datagrid control in my view.

Does anyone know of a more MVVM friendly mechanism to do excel exports (preferable based on the collection the grid is bound to) using the Infragistics libraries?

like image 553
Dav Evans Avatar asked Mar 06 '26 16:03

Dav Evans


2 Answers

Due to the required reference to the grid, as you know, you should not put the logic into the View Model. You just need to handle the Export command in your code-behind. There is nothing conceptually wrong, or anti-MVVM, about doing this: this particular logic just happens to be View-specific.

like image 196
HappyNomad Avatar answered Mar 08 '26 07:03

HappyNomad


The datagrid is part of view and export to excel is a feature of this grid. There is no involvement of ViewModel at all. Its a pure case of View activity. Considering this as apure view feature, you cannot / need not handle the Export Command in ViewModel but in the View (code-behind) itself. Tomorrow if you replace this datagrid with another datagrid, the export to excel feature will also go, since its provided by infragistics. Hence your view model is not supposed to do anything. However if you want to implement a generic and independent functionality which is not specific to infragistics, you may do it in the ViewModel (Because its generic and not dependent of infragistics).

like image 38
Pradeep Avatar answered Mar 08 '26 07:03

Pradeep



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!