Set Uri to TRDX in WPF Report viewer programmatically

1 Answer 68 Views
.NET Core Report Designer (standalone) Report Viewer - WPF
Jeroen
Top achievements
Rank 1
Iron
Jeroen asked on 22 May 2023, 01:09 PM

Hello,

we've upgraded to VS2022 and .NET 7.

The reports are giving us a lot of problems, it looks like we have too rebuild them in the Standalone Report Designer. Import fails

The default Telerik WPF ReportViewer has this


<tr:ReportViewer Grid.Row="0" x:Name="ReportViewer1" HorizontalAlignment="Stretch" EnableAccessibility="true">
        <tr:ReportViewer.ReportSource>
		<telerikReporting:UriReportSource Uri=""/>
	</tr:ReportViewer.ReportSource>
</tr:ReportViewer>

 

 

Can we change the Uri programmatically in a MVVM project? Something like


<tr:ReportViewer Grid.Row="0" x:Name="ReportViewer1" HorizontalAlignment="Stretch" EnableAccessibility="true">
    <tr:ReportViewer.ReportSource>
	<telerikReporting:UriReportSource Uri="{Binding ReportSource}"/>
    </tr:ReportViewer.ReportSource>
</tr:ReportViewer>


where reportsource is ExampleReport.trdp

 

Jeroen

1 Answer, 1 is accepted

Sort by
0
Accepted
Jeroen
Top achievements
Rank 1
Iron
answered on 23 May 2023, 06:25 AM

Figured it out.

 

In the viewmodel I create the InstanceReportSource using

 public static readonly PropertyData ReportSourceProperty = RegisterProperty("MyReportSource", typeof(InstanceReportSource));
        public InstanceReportSource MyReportSource { get { return GetValue<InstanceReportSource>(ReportSourceProperty); } set { SetValue(ReportSourceProperty, value); } }
        public ReportWindowViewModel(List<TargetGroupItem> targetGroupItem) 
        {

            var reportPackager  = new ReportPackager();
            var reportProcessor = new ReportProcessor();
            Telerik.Reporting.Report report = null;

            using (var sourceStream  = System.IO.File.OpenRead(AppDomain.CurrentDomain.BaseDirectory + "/Reports/CustListComment.trdp"))
            {
                report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
            }

            report.DataSource = targetGroupItem;            

            MyReportSource = new InstanceReportSource() { ReportDocument = report };

 

And in the view


<Grid x:Name="LayoutRoot">
		<Grid Margin="20" >
			<Grid.RowDefinitions>
				<RowDefinition Height="*" />
			</Grid.RowDefinitions>

            <tr:ReportViewer Grid.Row="0" x:Name="ReportViewer1" HorizontalAlignment="Stretch" EnableAccessibility="true" 
                             ReportSource="{Binding MyReportSource}">				
			</tr:ReportViewer>

		</Grid>
	</Grid>

 

I use the Catel framework for handling the INotifyPropertyChanged

Tags
.NET Core Report Designer (standalone) Report Viewer - WPF
Asked by
Jeroen
Top achievements
Rank 1
Iron
Answers by
Jeroen
Top achievements
Rank 1
Iron
Share this question
or