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.
- Download and install the new version of the WPF controls.
- Download and install the new version of Telerik Reporting.
- Open Visual Studio and load the solution that you want to upgrade.
- Run the upgrade wizard for the WPF controls by following these steps or manually update the references and binding redirects for the WPF controls.
- Run the upgrade wizard for the Telerik Reporting libraries using these steps or manually update the references and binding redirects for the WPF controls.
- Since Telerik is moving toward implicit styling for their WPF controls add the following XAML files found in
[INSTALLDIR]\Telerik\Reporting Q2 2014\Wpf\Themesto your solution.
- Merge these resource dictionaries at the APP level by adding the following to the Application.Resources section of your App.xaml file
<Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <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"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources>
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.
- The style template for the report viewer is embedded in the Telerik.ReportViewer.Wpf.xaml file.
- 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.
- 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.
- If you bind any commands to the ReportViewer’s tool-bar, the PageScriollView will need to have focus.
- The newest ReportViewer implements a new ViewMode attribute that you can read more about here.
To upgrade in this scenario, use the following steps:
- Follow all the steps in scenario 1.
- Extract the style template for the ReportViewer from the Telerik.ReportViewer.Wpf.xaml file.
- Edit the extracted template to create the style you need for your application.
- 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);
- 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"); scrollViewer.Focus();
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.