before I was getting the ReportViewerModel doing so :
var reportViewerModel = reportViewer.DataContext as ReportViewerModel;
Today after Q1'11 upgrade I get an Enum I define in the Main page hosting it.... why this happen?
Thanks
13 Answers, 1 is accepted
This change is done on purpose in order to allow binding of report viewer properties directly to an inherited DataContext (see the release notes). If you have to get the ReportViewerModel then you should use the report viewer's first child instead. Here is a sample code snippet which shows how to achieve this:
var layoutRoot = (FrameworkElement)VisualTreeHelper.GetChild(
this
.ReportViewer1, 0);
var rvm = (ReportViewerModel)(layoutRoot.DataContext);
This works both for WPF and Silverlight report viewers.
However the ReportViewerModel in both Silverlight and WPF report viewers is intended for internal use by the controls and we will appreciate if you share with us your particular case that demands the use of the ReportViewerModel.
All the best,
Chavdar
the Telerik team
If it's similar to the use case I'm in right now, we need a way to refresh the report using parameters that can only be set from outside of the ReportViewer...and we're using Silverlight MVVM.
The previous version allowed you to do this, and it worked quite well:
((ReportViewerModel)
this
.InvoiceReportViewer.DataContext).RefreshReportCommand.Execute(
null
);
Now, as you mentioned, that breaks.
The issue with the work-around now is that my report does not have a child and the call to GetChild(ReportViewer, 0) now breaks with this error:
Specified argument was out of the range of valid values.
Parameter name: childIndex
I don't want to un-upgrade all the reports but that's what I'll have to do I guess...
Here is a working sample snippet tested on our demos that illustrates this approach:
public
partial
class
MainPage : UserControl
{
public
MainPage()
{
InitializeComponent();
}
void
button1_Click(
object
sender, RoutedEventArgs e)
{
this
.ReportViewer1.RefreshReport();
}
}
static
class
ReportViewerExtensions
{
public
static
void
RefreshReport(
this
ReportViewer reportViewer)
{
var layoutRoot = (FrameworkElement)VisualTreeHelper.GetChild(reportViewer, 0);
var viewerModel = (ReportViewerModel)layoutRoot.DataContext;
var refreshCommand = viewerModel.RefreshReportCommand;
if
(refreshCommand.CanExecute(
null
))
{
refreshCommand.Execute(
null
);
}
}
}
Hope it helps.
Regards,
Steve
the Telerik team
If e.PropertyName = "IsParametersAreaVisible" _
AndAlso CType(reportv.DataContext, ReportViewerModel).IsParametersAreaVisible _
AndAlso m_bOverwriteReportParameters Then
CType(reportv.DataContext, ReportViewerModel).IsParametersAreaVisible = False
m_bOverwriteReportParameters = False
End If
I am trying to make sense of how MVVM fits into the Silverlight ReportViewer but I am just too unfamiliar with Telerik Reports to make any sense of it.
I've logged a support ticket under my account regarding, but this article seems that you are saying that the DataContext will inherit in Silverlight.
Am I suppose to create the Report with an Objectdatasource or without, any nice walkthroughs on this just simply explaining ReportViewer, Silverlight and MVVM. I can imagine if you know what goes where it is really simple but I am unable to get any data shown in my report from my ViewModel.
I have a report with no datasource, and set the DataContext of the Report Viewer to my Model which is an ObservableCollection of a class with Properties. I then also created a Binding on the TextBlock in the Report to a string of the Property. Pretty much what you would do in a normal RadGridView.
Thanks,
Anton
For now Telerik Reports reside on the server and the Silverlight ReportViewer always requires the Telerik Reporting WCF Service, which acts as a communication interface between the client (Silverlight) and the report server. Currently the reporting engine is not compatible with Silverlight and it requires .NET framework to perform its operations. Thus the report can't utilize the Silverlight's DataContext but instead rely on the datasource components that are defined in the report definition.
You may find useful the following help resources:
Anyway we already have a couple of ideas how to improve the integration of the Reporting engine with Silverlight, but due to some limitations of the framework we will stay with the report service for now. All the best,
Peter
the Telerik team
I'm working with the Reporting WCF Services and ReportViewerModel. I want to change an exception error that I get from a WCF service call. The thing is that I have my reports in another server and I'm doing some testing regarding reports service connection, so my test consists in trying to render a report simulating a lost of service connection. Once that happens, I got a big timeout exception inside the Report Designer that I'd like to change to an user-friendly message.
I've been using the ReportViewerModel.Error property to set my custom message in the service callback, but sometimes the Error property gets override for the original exception message.
How could I display custom messages inside the report designer?
How can I handle those types of custom error message?
Thanks in advance.
UJazz.
The code should be executed when the ReportViewer is fully loaded in the visual tree.
Please consider the following example with printing:
private
ReportViewerModel m_viewerModel;
private
ReportViewerModel ViewerModel
{
get
{
if
(m_viewerModel ==
null
&& VisualTreeHelper.GetChildrenCount(
this
.ReportViewer1) > 0)
{
var layoutRoot = (FrameworkElement)VisualTreeHelper.GetChild(
this
.ReportViewer1, 0);
m_viewerModel = (ReportViewerModel)layoutRoot.DataContext;
}
return
m_viewerModel;
}
}
public
MainPage()
{
InitializeComponent();
ReportViewer1.RenderBegin += ReportViewer1_RenderBegin;
}
void
ReportViewer1_RenderBegin(
object
sender, RenderBeginEventArgs args)
{
//parameters passing
this
.ViewerModel.PropertyChanged +=
this
.ViewerModel_PropertyChanged;
}
private
void
ViewerModel_PropertyChanged(
object
sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if
(e.PropertyName ==
"State"
&& IsReadyToPrint())
{
this
.ViewerModel.PropertyChanged -=
this
.ViewerModel_PropertyChanged;
this
.PrintReport();
}
}
private
bool
IsReadyToPrint()
{
return
this
.ViewerModel.State == ReportViewerStates.ViewerPage;
}
private
void
PrintReport()
{
this
.m_viewerModel.PrintReportCommand.Execute(
null
);
}
I hope this helps you.
All the best,Stef
the Telerik team
Hello everyone,
may it be possible that "(FrameworkElement)VisualTreeHelper.GetChild(this.ReportViewer1, 0);" isn't working any more in 2015 and newer releases? I used this way described in the last post some years, but now with a newer Reporting Version it seems to be broken.
Any advises how to deal with this situation now?
Regards,
Michael
The WPF|Silverlight ReportViewer control's ReportViewerModel is for internal usage only, but you can use the exposed viewer's API to perform the same tasks - WPF ReportViewer Members and Silverlight ReportViewer Members.
If you are missing a functionality from the ReportViewerModel, please let us know.
In addition, please check the updated approach for configuring the WPF|Silverlight ReportViewer in an application - WPF ReportViewer: Manual Setup and Silverlight ReportViewer: Setup.
Regards,
Stef
Telerik
Hello Stef,
thx for your reply. I already reviewed the Silverlight ReportViewer members, but no one of them can perform what is performed by the code i've posted. The most obvious was the "RefreshReport", but using this absolutly nothing happens ;)
So i didn't found a way of reproducing my functionality with the current available members of the ReportViewer.
Do you see a way how to do this?
Regards,
Michael
I am missing the whole context and where the given code snippet for hiding the parameters area is used, but I can suggest you the following:
- Use custom UI like Button that hides the viewer's parameters area;
- Use a viewer's event like RenderingEnd to hide the parameters area:
Private
Sub
ReportViewer1_RenderingEnd(sender
As
Object
, e
As
EventArgs)
ReportViewer1.ParametersAreaVisible =
False
End
Sub
Regards,
Stef
Telerik