I was watching Craig Shoemaker’s video blog post on Introduction to XamDataGrid Excel Exporting and was excited that he started things out with a ViewModel but the export code was all performed in a code-behind. This left me wanting more. The problem is that Infragistics‘ DataPresenterExcelExporter requires you to pass a DataPresenterBase object (implemented by the XamDataGrid) as a parameter. This makes sense as the power of the DataPresenterExcelExporter feature is that whatever formatting you have put in place on your grid is what gets exported, saving me being asked to try and replicate a user’s grouping, sorting, or what-not in Excel.
So, I used a UserControl, and PRISM‘s generic DelegateCommand (one of my favorites) to pass the XamDataGrid instance through to my ViewModel and was able to move toward a more pure MVVM implementation of the export to excel feature.
You can find the complete sample here: