This is a migrated thread and some comments may be shown as answers.

Execute WPF ReportViewer functions programmatically

4 Answers 195 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
ClausDC
Top achievements
Rank 1
Iron
Iron
ClausDC asked on 23 Jan 2012, 03:26 PM
Is there a way to execute functions (next page, previous page, first page, toggle ViewMode, print etc.) of the WPF ReportViewer programmatically?

We embed the viewer in a larger UI application and we want to use the viewer to display the report, but the controls of our own enveloping application to control its functions.

When I look at the ReportViewer source code, its controls bind to its view model which in turn is private. Is there no way to execute the "next page" command (for example) programmatically externally?

4 Answers, 1 is accepted

Sort by
0
ClausDC
Top achievements
Rank 1
Iron
Iron
answered on 24 Jan 2012, 09:43 AM
I mean essentially the functionality that is already in the WinForms Viewer.
0
IvanY
Telerik team
answered on 24 Jan 2012, 07:13 PM
Hello Claus,

In order to programmatically control the buttons in WPF you have first to extract the ReportViewerModel from the DataContext of the ReportViewer. In the model you will find all the commands of the buttons you need. This is a sample how to extract the ReportViewerModel:

var layoutRoot = (FrameworkElement)VisualTreeHelper.GetChild(this.ReportViewer1, 0);
var reportViewerModel = (ReportViewerModel)(layoutRoot.DataContext);

Using the ReportViewerModel you can bind your buttons to the commands in your XAML for example. However ReportViewerModel in both Silverlight and WPF report viewers is intended for internal use by the controls and a better approach (if only customization of the buttons is required) would be to edit the templated controls in Blend. For additional information you can check the Creating Style in Expression Blend help article. General information on styling templated controls is available in the Styling a control that supports templates MSDN article.

Regards,
IvanY
the Telerik team

Q3’11 of Telerik Reporting is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

0
ClausDC
Top achievements
Rank 1
Iron
Iron
answered on 25 Jan 2012, 08:59 AM
Thanks.

The problem with editing the templated controls is that this is limited to the controls in the viewer itself. I cannot use a button outside of the viewer which calls a viewer functionality like "next page" which is exactly what I want to do.

I agree that the first solution (to use the internal ViewModel) is not recommendable, in fact I had and earlier solution which used reflection to access the internal ViewModel but I dismissed this as too unstable.

Are there plans to make the WPF viewer functions like "next page", "previous page" etc. accessible like they are with the WinForms viewer? We really need this because as it stands now, I have to use the WinForms viewer in a WinFormsHost-Control in our WPF application.
0
IvanY
Telerik team
answered on 25 Jan 2012, 05:36 PM
Hi Claus,

We would advise you to extract the ReportViewerModel instead of mixing WPF and Win Forms applications.

As for making the Commands in WPF accessible, we certainly consider to include all functionality that improves the user experience and flexibility of Telerik Reporting, but we cannot engage with a specific time frame.

Greetings,
IvanY
the Telerik team

Q3’11 of Telerik Reporting is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

Tags
General Discussions
Asked by
ClausDC
Top achievements
Rank 1
Iron
Iron
Answers by
ClausDC
Top achievements
Rank 1
Iron
Iron
IvanY
Telerik team
Share this question
or