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

ReportViewer for WPF

4 Answers 295 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Alen
Top achievements
Rank 1
Alen asked on 04 Dec 2012, 12:28 PM
For the application we're currently developing we'd like to use the Telerik Reporting.These last days I was testing it and how well it would suit our needs. Our application is running in WPF on .NET 4.0 and has its own look and feel. Now I was searching your forum on how to apply changes to the ReportViewer class and I came to know that you have to change the style of the ReportViewer itself, which wouldn't be a big deal. Since our application has its own Ribbonbar, we wanted to remove the Toolbar from the ReportViewer and integrate it into our application. Now I've figured out that the ReportViewer has no commands which support the functionality identical to those of the integrated Toolbar. On the forum you could find out that the ReportViewer was implemented using the MVVM-pattern.
So I'd like to know if there is a way to accomplish the needed task? Am I able to access the commands of the ReportViewerModel from ReportViewer (e.g. MoveToNextPageCommand, etc.) or do I have to write my own UserControl that has a ViewModel inheriting from ReportViewerModel?
An answer to this cause would be appreciated.

Regards
Alen

4 Answers, 1 is accepted

Sort by
0
Accepted
IvanY
Telerik team
answered on 07 Dec 2012, 03:08 PM
Hello Alen,

The ReportViewerModel is intended for internal purposes only and therefore the commands are not exposed so that you can easily use them. However there is an available workaround that will suite your needs - in case you use it please have in mind that the ReportViewerModel might change in a subsequent version of Telerik Reporting and you will have to manually change your code so that it works with the new version.

The workaround is to extract the ReportViewerModel from the DataContext of the ReportViewer. Once you do that you will have access to the commands of the Report Viewer and you can invoke them in your own code. Check out the snippet below:
var layoutRoot = (FrameworkElement)VisualTreeHelper.GetChild(this.ReportViewer1, 0);
var reportViewerModel = (ReportViewerModel)(layoutRoot.DataContext);

I hope that helps.

Kind regards,
IvanY
the Telerik team

HAPPY WITH TELERIK REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!

0
Alen
Top achievements
Rank 1
answered on 10 Dec 2012, 09:14 AM
Hello IvanY,

thank you very much. Your answer was exactly what I needed and helped me accomplish my task.

Kind Regards,
Alen
0
Stefan
Top achievements
Rank 1
answered on 13 Jun 2018, 09:21 AM

Hello,

I tried the approach suggested by IvanY but can't cast layoutRoot.DataContext to a ReportViewerModel, as this class is internal.
Is there a workaround for this?

Best Regards!

0
Todor
Telerik team
answered on 18 Jun 2018, 07:22 AM
Hello Stefan,

Starting with Q3 2014, the WPF ReportViewer's ReportViewerModel is internal and should NOT be used. Instead you can use the exposed viewer's API.

From Q1 2014 Telerik Reporting WPF/Silverlight ReportViewer controls use only implicit styles. For more details please refer to the Setting a theme of the WPF/Silverlight Report Viewer (Q1 2014 and later) blog post and How to: Add report viewer to a WPF application help article.

The file related to the the viewer is the Telerik.ReportViewer.Wpf.xaml from the proper theme - for example C:\Program Files (x86)\Progress\Telerik Reporting R2 2018\Wpf\Themes\ExpressionDark. It can be customized according to your needs. The commands can be  bound to custom buttons -  check the default code of Telerik.ReportViewer.Wpf.xaml for hints on implementation.

Regards,
Todor
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Alen
Top achievements
Rank 1
Answers by
IvanY
Telerik team
Alen
Top achievements
Rank 1
Stefan
Top achievements
Rank 1
Todor
Telerik team
Share this question
or