Updating Telerik Reports from Q1 2011 to Q2 2014

Instructors can impart only a fraction of the teaching. It is through your own devoted practice that the mysteries of the Art of Peace are brought to life.”
– Morihei Ueshiba

The company I work for uses Telerik reporting for report generation and Telerik WPF user controls for charting and other neat stuff as part of our development tools. This past week I had the great opportunity to upgrade the Telerik tool libraries from the Q1 2011 version to the tools to the Q2 2014 version.

The product manager had decided to forgo this update until it was absolutely necessary. It became vitally necessary when a new report was requested by a client and it was discovered that in order to use Telerik’s report designer in Visual Studio 2013 we would have to update the libraries for the tools. The good news was that we were on a support contract and Telerik provides an update wizard to do most of the work in updating assemblies.

If you need to update your Telerik libraries, then there are two ways this can work out for you. I’ll start with the best case scenario first.

Scenario 1: You are using Telerik’s tools straight out of the box.

If the project you are working on uses the Telerik tools right out of the box, or with minimal style changes by creating new styles based on the Telerik styles right out of the box, then your life has been made really simple by Telerik. In my case the project I am working on uses the Telerik WPF Windows Controls and Telerik Reporting. To update these all you need to do is follow these steps.

  1. Download and install the new version of the WPF controls.
  2. Download and install the new version of Telerik Reporting.
  3. Open Visual Studio and load the solution that you want to upgrade.
  4. Run the upgrade wizard for the WPF controls by following these steps or manually update the references and binding redirects for the WPF controls.
  5. Run the upgrade wizard for the Telerik Reporting libraries using these steps or manually update the references and binding redirects for the WPF controls.
  6. Since Telerik is moving toward implicit styling for their WPF controls add the following XAML files found in [INSTALLDIR]\Telerik\Reporting Q2 2014\Wpf\Themes to your solution.
    • System.Windows.xaml
    • Telerik.Windows.Controls.xaml
    • Telerik.Windows.Controls.Input.xaml
    • Telerik.Windows.Controls.Navigation.xaml
    • Telerik.ReportViewer.Wpf.xaml
  7. Merge these resource dictionaries at the APP level by adding the following to the Application.Resources section of your App.xaml file
        <ResourceDictionary Source="/Themes/System.Windows.xaml"/>
        <ResourceDictionary Source="/Themes/Telerik.Windows.Controls.xaml"/>
        <ResourceDictionary Source="/Themes/Telerik.Windows.Controls.Input.xaml"/>
        <ResourceDictionary Source="/Themes/Telerik.Windows.Controls.Navigation.xaml"/>
        <ResourceDictionary Source="/Themes/Telerik.ReportViewer.Wpf.xaml"/>

Since everything else is out of the box you application should compile and run, albeit with a few other possible minor code changes.

Note: The method fro steps 6 and 7 were extracted from the article How to: Add report viewer to a WPF application.

Scenario 2: You have made significant style changes directly to one of the Telerik Templates

If you have made significant style changes directly to one of the Telerik templates, say for example the Report Viewer template, then may God have mercy on your soul. I cannot speak for any other templates you may have changed, but if you have changed the Report Viewer template in a version of Telerik reporting prior to Q1 2014, then the following bit may be useful to you. Before I go through the steps for upgrading your customized styles there are 5 bits of information that you should take away from this discussion.

  1. The style template for the report viewer is embedded in the Telerik.ReportViewer.Wpf.xaml file.
  2. The ReportViewerModel constructor was changed to an internal constructor between Q1 2011 and Q1 2013, so you can’t use it anymore if you were in the past.
  3. If you need access to the ReportViewerModel for any reason, you will have to wait until the ReportViewer Loaded event has occurred and then walk the visual tree down to the first child of the ReportViewer and cast its DataContext as a ReportViewerModel to retrieve it.
  4. If you bind any commands to the ReportViewer’s tool-bar, the PageScriollView will need to have focus.
  5. The newest ReportViewer implements a new ViewMode attribute that you can read more about here.

To upgrade in this scenario, use the following steps:

  1. Follow all the steps in scenario 1.
  2. Extract the style template for the ReportViewer from the Telerik.ReportViewer.Wpf.xaml file.
  3. Edit the extracted template to create the style you need for your application.
  4. If you need access to the ReportViewerModel for any reason, add a Loaded event handler to the ReportViewer and use the following code to get access to it:
    var layoutRoot = (FrameworkElement)VisualTreeHelper.GetChild(this.ReportViewer1, 0);
    var rvm = (ReportViewerModel)(layoutRoot.DataContext);
  5. If you have added command bindings to any of the ReportViewer button styles, add a Loaded event handler to the ReportViewer, or use the one created in the previous step if you did so, and add the following code:
    var scrollViewer = VisualHelperEx.FindVisualChildByName<ScrollViewer>(ReportViewer, "PageScrollViewer");

With a few other possible minor code changes you should now be able to compile and run your code.

If you till are having issues, first, I am sorry, and second, stay calm and patient. Telerik’s documentation is not what it could be and it took me a week to get my styles to work. I hope my experience with this might help someone out there someday.