I've read all the documentation, trolled the board and Google and have burnt/lost 8 solid hours trying to get 2012.2 xamReportViewer to use an instance of the business object class used during design of the .igr report. The help/documentation only seems to provide ways to change connection strings to sqlDataProvider - or in the case of objects, examples "generate a "new" object in the constructor of a ReportDataServiceProvider - which is of absolutely no help - since I want to pass the report an existing instance of the object. I've tried the viewer "data-binding" angle as well, but have not found any configuration that works at injecting the object.
This is the reference to data-binding the viewer that I couldn't get to work
<ig:ClientRenderSettings > <ig:ClientRenderSettings.DataSources> <ig:DataSource TargetDataSource="Orders" ItemsSource="{Binding ElementName=domainDataSource}" /> </ig:ClientRenderSettings.DataSources> </ig:ClientRenderSettings>
HERE IS THE SIMPLIFIED SCENARIO:
View has fields that are bound to an instance of a model called mymodel. (Let's say FirstName and LastName are the properties of model)
When user clicks "Print", I need an instance of xamReportViewer to generate a report using mymodel (the instance of model filled by my view) as it's itemsource.
It seems like it should be such an easy (and obvious) thing to accomplish, but I've found it impossible and (obviously frustrating).
Can someone please help with a practical example.
Thanks in advance for any help you can offer.
Luis,
Thank you for helping to connect the dots. I got it working!
At your service,
Jeff
Hi,
The properties you can use for your object datasource must be collections of some type, in your case it should be a collection of MyModel. The easiest thing to do would be adding such a property to your ViewModel, then binding it to the viewer's datasources.
I'm attaching a solution that shows how this could be implemented. In this case I have a class DataItem that has the propeties FirstName and LastName. The ViewModel for the XAML has:
- The DataItem you are using: public DataItem Item
- A collection property that returns a collection with just one element: public IEnumerable<DataItem> Items { get { return new List<DataItem> { item }; } }
Then you configure the DataSources of the XamReportViewer like this: <ig:ClientRenderSettings.DataSources> <ig:DataSource TargetDataSource="DataItem" ItemsSource="{Binding Items}"></ig:DataSource> </ig:ClientRenderSettings.DataSources>
Let me know if this is what you were looking for.
Regards,Luis