Here is also a tutorial on infragistics WPF Report (1)

Source: Internet
Author: User

Preface

Infragistics report is a flexible report control. It is better to adjust the page control than Microsoft's rdlc control at least on page printing.


Here we use the trial version of infragistics ultimate v14.1

The development tool is a visual Studio 2013 framework 4.0 WPF windows application.


Add Report

Drag xamreportviewer from the toolbar on the left to the form on the right.

<ig:XamReportViewer HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></ig:XamReportViewer>

The system will automatically add references, remember these references, and package these references at the time of release, so that no problems will occur during client running.



1. First define a person class to 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 will define another mainwindowviewmodel to associate the datacontext of mainwindow. XAML.

In mainwindow. XAML, we need to create a new mainwindowviewmodel object and assign values to the attributes of the object so that the corresponding parameters can be bound to the report. This is the mvvm mode.

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 report

Add Data Source

1. Create a report. After infragistics is installed, an infragistics item is added when a new project is added. Add a report as shown in the figure.


2.Create a data source

On the report data Explorer toolbar, right-click and choose datasource-add new data source,


In the pop-up window, select "Object Data Source" and click Next,


Select the defined mainwindowviewmodel. CS,Note that after creating and editing mainviewmodel. CS, You need to compile it to display it only when adding the data source. Otherwise, it will not be displayed.


Add Parameters

Adding parameters is relatively simple. Right-click parameter from report data explorer on the left and select "add static Value List parameter". Enter the parameter name.


After adding the data source, click OK and drag the data source and parameters to the report area on the right.


Bind Parameters

Code after the bound Parameter

        <ig:XamReportViewer HorizontalAlignment="Stretch" VerticalAlignment="Stretch">            <ig:XamReportViewer.RenderSettings>                <ig:ClientRenderSettings  DefinitionUri="/InfragisticsReportSample;component/Person.igr">                    <ig:ClientRenderSettings.DataSources>                        <ig:DataSource 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" indicates that the bound collection type is person.

Itemssource = "{binding personcollection}" indicates that the bound data source is a personcollection.

Parametername = "printdate" indicates that the parameter name created in the report is printdate, and parametervalue = {binding printdatetime} indicates the property bound to printdatetime.


Add data

When you create a mainwindowviewmodel, specify the data source 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 = "Dorado ADREAM"; p. age = 99; p. profilephoto = getbyteimage ("doraemon.jpg"); Model. personcollection. add (p); P = new person (); p. name = "ala lei"; 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, filemode. open); byte [] bydata = new byte [FS. length]; FS. read (bydata, 0, bydata. length); FS. close (); Return bydata ;}}
Final Report Result


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.