Also a tutorial on the use of Infragistics WPF report (i)

Source: Internet
Author: User

Objective

Infragistics Report is a flexible reporting control that controls the page better than Microsoft's RDLC controls, at least on page printing.


The Infragistics Ultimate v14.1 trial version is used here.

The development tool is a visual Studio Framework 4.0 WPF Windows application.


Add to report

Drag the Xamreportviewer from the left-hand toolbar to the right-side window.

<ig:xamreportviewer horizontalalignment= "Stretch" verticalalignment= "Stretch" ></ig:XamReportViewer>

The system will take the initiative to join the reference, remember these references, publish the time, the reference package. This will not fail when the client executes.

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvdzu5odc5mjez/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">


1. First define a class of person, implement the Inofifypropertychanged interface.

   public class Person:inotifypropertychanged {#region Implement of inotifyproeprtychanged.        public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged (String propertyname) {PropertyChangedEventHandler handler = this.            propertychanged;            if (handler! = null) {Handler (this, new PropertyChangedEventArgs (PropertyName));        }} #endregion private string _name;        private int _age;        Private byte[] _profilephoto;            public string Name {get {return _name;}                set {_name = value;            OnPropertyChanged ("Name");            }} public int age {get {return _age;} set {_age = value; OnPropertyChanged ("Age");            }} public byte[] Profilephoto {get {return _profilephoto;} set {_profilephoto = value; OnPropertyChanged ("ProfIlephoto "); }        }    }


2. We then define a Mainwindowviewmodel, which is used to correlate the DataContext of MainWindow.xaml.

In MainWindow.xaml we want to create a Mainwindowviewmodel entity and assign values to the attributes in the entity. This is enough to bind the corresponding parameters to the report. That is, the MVVM pattern.

public class Mainwindowviewmodel:inotifypropertychanged {#region Implement of inotifyproeprtychanged.        public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged (String propertyname) {PropertyChangedEventHandler handler = this.            propertychanged;            if (handler! = null) {Handler (this, new PropertyChangedEventArgs (PropertyName));        }} #endregion private observablecollection<person> _personcollection;        Private DateTime _printdatetime;            Public observablecollection<person> Personcollection {get {return _personcollection;}                set {_personcollection = value;            OnPropertyChanged ("Personcollection");            }} public DateTime Printdatetime {get {return _printdatetime;} set {_printdatetime= value;            OnPropertyChanged ("Printdatetime"); }        }    }

Create a report

Join the data source

1. Create a report, after installing Infragistics, the new project, there will be a infragistics, as seen in the diagram, add the report.


2. Create a data source

From the Report Data Explorer toolbar, right-click, select Datasource-add new Data Source,


Select "Object Data Source" in the form that pops up in the back, click Next,

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvdzu5odc5mjez/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center "width=" "height=" >

Choose the MainWindowViewModel.cs that we just defined, and here we need to note that after creating the edit MainViewModel.cs, it is necessary to compile it and display it when the data source is added. Otherwise it will not be displayed.

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvdzu5odc5mjez/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">

Join the number of references

The relatively simple addition of the parameters, from the left side of the report Data Explorer right-click Parameter, select "Add Static Value List Parameter", enter the name of the parameter can be.


Once you're done, click OK, and then drag the data source to the right side of the report area.


Binding the number of references

Code after the binding's parameters

        <ig:xamreportviewer horizontalalignment= "Stretch" verticalalignment= "Stretch" >            <ig: xamreportviewer.rendersettings>                <ig:clientrendersettings  definitionuri= "/ Infragisticsreportsample;component/person.igr ">                    <ig:ClientRenderSettings.DataSources>                        <ig :D atasource targetdatasource= "person" itemssource= "{Binding personcollection}"/>                    </ig: clientrendersettings.datasources>                </ig:ClientRenderSettings>            </ig: xamreportviewer.rendersettings>            <ig:XamReportViewer.Parameters>                <ig:parameter Parametername= "PrintDate" parametervalue= "{Binding printdatetime}"/>            </ig:xamreportviewer.parameters >        </ig:XamReportViewer>

Targetdatasource = "Person" refers to the type of collection that is bound to person

ItemsSource = "{Binding personcollection}" refers to a bound data source of personcollection

ParameterName = "PrintDate" means the name of the reference we create in the report is called printdate, and ParameterValue = {Binding Printdatetime} refers to the property of the binding printdatetime.


Add data

When you create a mainwindowviewmodel, you specify the data source, and you are able to display the report.


       Public MainWindow () {InitializeComponent ();                        Mainwindowviewmodel model = new Mainwindowviewmodel (); Model.            Personcollection = new observablecollection<person> (); Model.            Printdatetime = DateTime.Now;            Person p = new person ();            P.name = "Dora a Dream";            P.age = 99;            P.profilephoto = Getbyteimage ("doraemon.jpg"); Model.            Personcollection.add (P);            p = new person ();            P.name = "ala";            P.age = 100;            P.profilephoto = Getbyteimage ("arale.jpg"); Model.            Personcollection.add (P); This.        DataContext = model; } public byte[] Getbyteimage (string imagepath) {FileStream fs = new FileStream (ImagePath, Filemo De.            Open); byte[] Bydata = new Byte[fs.            Length]; Fs.            Read (bydata, 0, bydata.length); Fs.            Close ();        return bydata; }    }
The final report results


Also a tutorial on the use of Infragistics WPF report (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.