This is a migrated thread and some comments may be shown as answers.

Report to print MVVM

6 Answers 83 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Cynthia
Top achievements
Rank 1
Cynthia asked on 26 Nov 2019, 05:23 PM

Hi, I need suport to pass my telerik report to MVVM pattern

right now my report is send to the printer, and all the programming is in xaml and their code behind:

in the user control xaml:

            <tr:ReportViewer Name="ReportViewer1" Width="0" Height="0" Grid.Column="0" Grid.Row="2">
                <tr:ReportViewer.ReportSource>
                    <telerikReporting:TypeReportSource TypeName="ReportLibrary, ReportLibrary" />
                </tr:ReportViewer.ReportSource>
            </tr:ReportViewer>

 

and in the user control code behind:

        public ucInventarioPTaVentas()
        {
            InitializeComponent();

            _InventarioVendido = new ObservableCollection<InventarioPTaVentasCL>();

            var TRS = new TypeReportSource();

            TRS.TypeName = typeof(rpMaterialVendido).AssemblyQualifiedName;
            ReportViewer1.ReportSource = TRS;

        }

        private void btnImprimir_Click(object sender, RoutedEventArgs e)
        {
            foreach (var item in grdColeccion.Items)
            {
                if (((InventarioPTaVentasCL)item).seleccionada)
                {
                    _InventarioVendido.Add((InventarioPTaVentasCL)item);
                }
            }
            
            #region ImprimeReporteDeVentas
            Report rpt;
            rpt = new rpMaterialVendido();

            rpt.DataSource = _InventarioVendido;

            Telerik.Reporting.InstanceReportSource instanceReportSource = new Telerik.Reporting.InstanceReportSource();
            instanceReportSource.ReportDocument = rpt;
            instanceReportSource.Parameters.Add("pCliente", cbClienteNombre.Text);
            ReportViewer1.ReportSource = instanceReportSource;

            ReportViewer1.PrintReport();

            #endregion
        }

 

But, for all my app, I using the MVVM pattern, obviously on my ViewModel I have the observablecollection and the parametrs needed to my report, and I don't know how make the report with the MVVM pattern, can you help me??

 

 

 

6 Answers, 1 is accepted

Sort by
0
Neli
Telerik team
answered on 29 Nov 2019, 01:04 PM

Hello Cynthia,

You may use the approach described in Using the WPF Report Viewer in an MVVM scenario KB article. 

The attached project demonstrates the solution.

Regards,
Neli
Progress Telerik

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 Feedback Portal and vote to affect the priority of the items
0
Cynthia
Top achievements
Rank 1
answered on 29 Nov 2019, 07:59 PM
well, i reviewed this solution before, but, on it I don't find how i can sent the report to the printer directly, without show it at the screen, as my report case, and how I can sent the DataSource and the parameters, and I can't runner it never, the project can't charge the references, I try to charger it manually, but, don't work...
0
Accepted
Neli
Telerik team
answered on 04 Dec 2019, 02:06 PM

Hi Cynthia,

If you would like to print the report directly, without showing it in the viewer, you can use the ReportProcessor.PrintReport Method. You may choose between:

PrintReport(ReportSource, PrinterSettings);

PrintReport(ReportSource, PrinterSettings, String).

Regards,
Neli
Progress Telerik

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 Feedback Portal and vote to affect the priority of the items
0
Cynthia
Top achievements
Rank 1
answered on 04 Dec 2019, 05:09 PM
ok, thanks a lot, an other more question, if I want to show the printer selecter on the screen, how I can do this?
0
Accepted
Neli
Telerik team
answered on 09 Dec 2019, 01:07 PM

Hi Cynthia,

Basically, if you don't specify the PrinterSettings or they are invalid, the Print dialog will be automatically displayed. For example:

reportProcessor.PrintReport(uriReportSource, null);

Regards,
Neli
Progress Telerik

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 Feedback Portal and vote to affect the priority of the items
0
Cynthia
Top achievements
Rank 1
answered on 10 Dec 2019, 03:25 PM
oooohhh, ok, thank you very much... I'm stay learning...
Tags
General Discussions
Asked by
Cynthia
Top achievements
Rank 1
Answers by
Neli
Telerik team
Cynthia
Top achievements
Rank 1
Share this question
or