
First of all, thanks for adding WPF support to Telerik.Reporting. Love it so far and am actually using it already in a clients project.
This project is a WPF MVVM project. So, using the samples I added this to my View.xaml:
<telerik:ReportViewer Name="reportViewer1" Margin="0" Report="{Binding Path=Report"/> |
Now, the ViewModel object contains the property report:
private Report _report; |
public Telerik.Reporting.Report Report |
{ |
get |
{ |
return _report; |
} |
set |
{ |
// Check if it's really a change |
if (value == _report) |
return; |
// Change Report |
_report = value; |
// Notify attached View(s) |
RaisePropertyChanged("Report"); |
} |
} |
Since the report get's its data from a business method (using a Webservice), I've put the code to create the report in the constructor for the ViewModel:
#region Constructor |
public SampleReportViewModel() |
{ |
// get data and create report here |
var report = new SampleReport(); |
var dataObject = myClass.GetData(); |
report.DataSource = dataObject; |
Report = report; |
} |
#endregion |
Any ideas on how to fix this?
Thanks!
Stefan Kamphuis
10 Answers, 1 is accepted
Attached you may find an example that illustrates how to bind the Report Viewer in a MVVM scenario. The most interesting part is that the ReportViewer control has already its own data context as it is build on the MVVM pattern itself (so is the Silverlight report viewer control). So you could not expect to use other data context.
In the provided example, the Window object is connected to the view model and the ReportViewer is bound to the view model through the windows's data context:
<
Window
x:Class
=
"CSharp.WpfDemo.Window2"
xmlns:telerik
=
"clr-namespace:Telerik.ReportViewer.Wpf;assembly=Telerik.ReportViewer.Wpf"
xmlns:telerikInput
=
"clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input"
xmlns:telerikControls
=
"clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
x:Name
=
"thisWindow"
Title
=
"Window2"
Height
=
"300"
Width
=
"300"
>
<
Grid
>
<
telerik:ReportViewer
x:Name
=
"ReportViewer1"
Report
=
"{Binding DataContext.Report, ElementName=thisWindow}"
/>
</
Grid
>
</
Window
>
All the best,
Svetoslav
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items.

The WPF report viewer is built using the MVVM pattern and has its own DataContext which it is bound to. This is the reason why the parent DataContext is not inherited.
Kind regards,
Chavdar
the Telerik team

I'm currently using Telerik.Reporting version 6.1.12.611.
Why are we getting this?
<
UserControl
x:Class
=
"MyCompanyName.MyProductName.ReportOverlayView"
xmlns:tr
=
"http://schemas.telerik.com/wpf"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
xmlns:telerikReporting
=
"clr-namespace:Telerik.Reporting;assembly=Telerik.Reporting"
>
<
Grid
>
<
tr:ReportViewer
Grid.Row
=
"1"
x:Name
=
"ReportViewer1"
telerik:StyleManager.Theme
=
"{Binding SelectedItem, ElementName=ThemeSelector}"
HorizontalAlignment
=
"Stretch"
>
<
tr:ReportViewer.ReportSource
>
<
telerikReporting:InstanceReportSource
ReportDocument
=
"{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}, Path=DataContext.Report }"
/>
</
tr:ReportViewer.ReportSource
>
</
tr:ReportViewer
>
</
Grid
>
</
UserControl
>
You can only bind to the ReportSource property; in your ViewModel you can pass the respective report source (InstanceReportSource in your case). It has to be something like this:
<
telerik:ReportViewer
x:Name
=
"ReportViewer1"
ReportSource
=
"{Binding MyReportSource}"
/>
In your ViewModel then you pass to that property your InstanceReportSource.
Greetings,
IvanY
the Telerik team
BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

I am trying to create reports in WPF using telerik report view. I am using busines object as data source but I am not able to show any data on report. I am sending you my simple project can you please take a look at it and see what I am missing .
Here is my code
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
// Creating and configuring the ObjectDataSource component:
Telerik.Reporting.ObjectDataSource objectDataSource = new Telerik.Reporting.ObjectDataSource();
objectDataSource.DataSource = typeof(Products); // Specifying the business object type
objectDataSource.DataMember = "GetProducts"; // Specifying the name of the data object method
objectDataSource.CalculatedFields.Add(new Telerik.Reporting.CalculatedField("FullName", typeof(string), "=Fields.Name + ' ' + Fields.ProductNumber")); // Adding a sample calculated field.
// Specify the parameters, their types and values
objectDataSource.Parameters.Add(new Telerik.Reporting.ObjectDataSourceParameter("color", typeof(string), "Silver"));
objectDataSource.Parameters.Add(new Telerik.Reporting.ObjectDataSourceParameter("productModelID", typeof(int), 23));
// Creating a new report
Telerik.Reporting.Report report = new Telerik.Reporting.Report();
// Assigning the ObjectDataSource component to the DataSource property of the report.
report.DataSource = objectDataSource;
// Use the InstanceReportSource to pass the report to the viewer for displaying
Telerik.Reporting.InstanceReportSource reportSource = new Telerik.Reporting.InstanceReportSource();
reportSource.ReportDocument = report;
// Assigning the report to the report viewer.
reportViewer1.ReportSource = reportSource;
// Calling the RefreshReport method in case this is a WinForms application.
reportViewer1.RefreshReport();
//this.reportViewer1.ReportSource = typeReportSource;
}
}
public class Product
{
public string Name { get; set; }
public string ProductNumber { get; set; }
public decimal ListPrice { get; set; }
public int ProductModelID { get; set; }
public string Color { get; set; }
}
public class Products
{
[DataObjectMethod(DataObjectMethodType.Select)]
public Product[] GetArraySource()
{
return this.GetAllProducts().ToArray();
}
[DataObjectMethod(DataObjectMethodType.Select)]
public ArrayList GetArrayListSource()
{
ArrayList arrayList = new ArrayList();
foreach (var product in this.GetAllProducts())
{
arrayList.Add(product);
}
return arrayList;
}
[DataObjectMethod(DataObjectMethodType.Select)]
public List<Product> GetAllProducts()
{
List<Product> products = new List<Product>();
products.Add(new Product()
{
Name = "Borehole Diameter",
ProductNumber = "11111111111",
ListPrice = 298,
ProductModelID = 7,
Color = "Red"
});
products.Add(new Product()
{
Name = "Borehole Diameter",
ProductNumber = "11111111111",
ListPrice = 298,
ProductModelID = 7,
Color = "Red"
});
products.Add(new Product()
{
Name = "Borehole Diameter",
ProductNumber = "11111111111",
ListPrice = 298,
ProductModelID = 7,
Color = "Red"
});
products.Add(new Product()
{
Name = "Borehole Diameter",
ProductNumber = "11111111111",
ListPrice = 298,
ProductModelID = 7,
Color = "Red"
});
return products;
}
// Gets products bellow a specified max price.
[DataObjectMethod(DataObjectMethodType.Select)]
public IList<Product> GetProducts(int productModelID, string color)
{
return this.GetAllProducts();
}
} and here is my xaml file
<Window x:Class="Telerik.Reproting.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="500" Width="683"
xmlns:telerik="clr-namespace:Telerik.ReportViewer.Wpf;assembly=Telerik.ReportViewer.Wpf"
xmlns:telerikReporting="clr-namespace:Telerik.Reporting;assembly=Telerik.Reporting" Loaded="Window_Loaded">
<Grid>
<telerik:ReportViewer Name="reportViewer1" Margin="-10,26,9.8,0" VerticalAlignment="Top" Height="355"/>
</Grid>
</Window>
Thanks
A report document is actually a template you can design using our Report Designers, which template is repeated for each record in the assigned to it data. There is no auto-generate feature, so you should have created previously a report definition using fields existing in the used as data source object.
More information about starting with Telerik Reporting can be found in our Quickstart help section, the videos accompanying our online demos, and the local examples installed by default under C:\Program Files (x86)\Telerik\Reporting <VERSION>\Examples\CSharp. There you can find an example with each of the available report viewers.
The attached WPF project illustrated a report bound at run-time to the data in your model.
Regards,
Stef
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Thanks it is working now.
Muhammad

Your example of:
<telerik:ReportViewer x:Name="ReportViewer1" ReportSource="{Binding MyReportSource}" />
Does not work.. The following error is encountered:
A 'Binding' cannot be set on the 'Report' property of type 'ReportViewer'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject. Howerver we are using "ReportSource" not "Report".
This is a major issue for us as we have spent days trying to use your examples to no avail. We upgraded and now cannot use any of our old reports.
Please use the demo project from the Reporting WPF MVVM Sample forum thread. The project must be upgraded locally as it uses older version of Telerik Reporting. Note that Telerik Reporting is synchronized with the official releases of Telerik UI for WPF, and you must upgrade both products - for more details about dependencies check the Upgrade Path articles.
In general, the WPF ReportViewer ReportSource property can be bound to a model's property which is of type ReportSource. Report properties are not dependency properties and must be handled in code.
The error in your case points that you are binding the viewer's deprecated Report property, instead of the viewer's ReportSource property. Thus please double-check all views and models settings to verify the viewer's Report property is not set elsewhere in code.
If you need further help, please use the support ticketing system to sen us more details about the problem.
Regards,
Stef
Telerik