Now that Telerik Reporting provides WPF support, let's see how to use it (a video on this topic is available as well):
Creating the application
- Install RadControls for WPF 2010 Q1 SP1 (download | release notes).
- Install the corresponding Telerik Reporting version.
- Create a new WPF application project in Visual Studio
- Add references to the following Telerik RadControls for WPF assemblies:
- Telerik.Windows.Controls
- Telerik.Windows.Controls.Input
- Telerik.Windows.Controls.Navigation
- Telerik.Windows.Data
NOTE: It is possible that the RadControls for WPF assemblies have a greater version than the one against which the WPF Report Viewer control was built. In this case you have to add appropriate assembly binding redirects (see Binding Redirects bellow). - Drag and drop the ReportViewer control from the toolbox in the WPF window. If the ReportViewer is not available in the toolbox, you can add it using the instructions from the How to add the WPF ReportVIewer to the toolbox bellow.
- Make sure your project references:
- Telerik.Reporting.dll
- Telerik.Reporting.XamlRendering.dll
- Assign a report to the Report property of the report viewer control. This can be done either declaratively or programmatically.
- Specifying a report declaratively using its assembly qualified name:
<
telerik:ReportViewer
Name
=
"reportViewer1"
Report
=
"Telerik.Reporting.Examples.CSharp.BarcodesReport, CSharp.ReportLibrary"
/>
- Setting the Report property at run time. The next code snippet illustrates how to assign a report to the WPF ReportViewer in the Window.Loaded event handler:
void
Window_Loaded(
object
sender, RoutedEventArgs e)
{
this
.reportViewer1.Report =
new
Telerik.Reporting.Examples.CSharp.BarcodesReport();
}
Adding the WPF ReportViewer to the Visual Studio toolbox
- While in Visual Studio, select a WPF window file in the solution explorer (e.g. Window1.xaml).
- Open the toolbox and add a new tab (or click on the General tab).
- Right click in the selected tab area and select Choose Items… This will open the Choose Toolbox Items dialog.
- Select the WPF Components tab, find and select the ReportViewer component from the Telerik.ReportViewer.Wpf assembly.
- Click OK.
Binding Redirects
In case you use Telerik RadControls for WPF version greater than 2010.1.422.35 you have to redirect all assemblies required by the Telerik WPF ReportViewer to their latest versions. To do this, add the following
bindingRedirects to your
app.config and replace the “
X.X.X.X” with the exact version of Telerik RadControls for WPF assemblies:
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
configuration
>
…
<
runtime
>
<
assemblyBinding
xmlns
=
"urn:schemas-microsoft-com:asm.v1"
>
<
dependentAssembly
>
<
assemblyIdentity
name
=
"Telerik.Windows.Controls"
culture
=
"neutral"
publicKeyToken
=
"5803cfa389c90ce7"
/>
<
bindingRedirect
oldVersion
=
"0.0.0.0-65535.65535.65535.65535"
newVersion
=
"X.X.X.X"
/>
</
dependentAssembly
>
<
dependentAssembly
>
<
assemblyIdentity
name
=
"Telerik.Windows.Controls.Input"
culture
=
"neutral"
publicKeyToken
=
"5803cfa389c90ce7"
/>
<
bindingRedirect
oldVersion
=
"0.0.0.0-65535.65535.65535.65535"
newVersion
=
"X.X.X.X"
/>
</
dependentAssembly
>
<
dependentAssembly
>
<
assemblyIdentity
name
=
"Telerik.Windows.Controls.Navigation"
culture
=
"neutral"
publicKeyToken
=
"5803cfa389c90ce7"
/>
<
bindingRedirect
oldVersion
=
"0.0.0.0-65535.65535.65535.65535"
newVersion
=
"X.X.X.X"
/>
</
dependentAssembly
>
</
assemblyBinding
>
</
runtime
>
…
</
configuration
>
Enjoy Telerik Reporting in your WPF app!