• North American Sales: 1-800-231-8588
  • Global Contacts
  • My Account
Infragistics Infragistics
Menu
  • North American Sales: 1-800-321-8588
  • My Account
    • Sign In/Register
  • Design & DevelopmentDesign & Develop
    • Best Value
      Infragistics Ultimate The complete toolkit for building high performing web, mobile and desktop apps.
      Indigo.Design Use a unified platform for visual design, UX prototyping, code generation and application development.
    • Web
      Ignite UI for Angular Ignite UI for JavaScript Ignite UI for React Ultimate UI for ASP.NET Indigo.Design
    • Desktop
      Ultimate UI for Windows Forms Ultimate UI for WPF
      Prototyping
      Indigo.Design
    • Mobile
      Ultimate UI for Xamarin Ultimate UI for iOS Ultimate UI for Android
    • Automated Testing Tools
      Test Automation for Micro Focus UFT: Windows Forms Test Automation for Micro Focus UFT: WPF Test Automation for IBM RFT: Windows Forms
  • UX
    • Indigo.Design Desktop Collaborative prototyping and remote usability testing for UX & usability professionals
    • Indigo.Design A Unified Platform for Visual Design, UX Prototyping, Code Generation, and App Development
  • Business Intelligence
    • Reveal Embedded Accelerate your time to market with powerful, beautiful dashboards into your apps
    • Reveal App Empower everyone in your organization to use data to make smarter business decisions
  • Team Productivity
  • Learn & Support Support
    • Help & Support Documents
    • Blogs
    • Forums
    • Product Ideas
    • Reference Applications
    • Customer Stories
    • Webinars
    • eBook & Whitepapers
    • Events
  • Free Trials
  • Pricing
    • Product Pricing / Buy Online
    • Renew Existing License
    • Contact Us
WPF
  • Product Platforms
  • More
WPF
WPF XML Databinding with the XamDataGrid
  • Blog
  • Files
  • Wiki
  • Mentions
  • Tags
  • More
  • Cancel
  • New
WPF requires membership for participation - click to join
  • WPF
  • Configuring the XamTab Control
  • Creating a Custom Summary for the XamDataGrid
  • Defining a Custom Path in the XamCarousel
  • Enabling Row Summaries in the XamDataGrid
  • Exporting the XamDataGrid to Excel
  • Hosting a WPF Control in a Windows Forms Application
  • Printing the XamDataGrid with Infragistics.Reports
  • Spell Checking in the XamDataGrid
  • Tangerine -- A WPF Reference Application
  • Using the Infragistics WinGrid in a WPF Application
  • Validation in the XamDataGrid
  • XamDataGrid :: Copying to Excel via the Clipboard
  • XML Databinding with the XamDataGrid

XML Databinding with the XamDataGrid

XML Data File

Start with having an XML Datasource for the purpose of this example we’ll use the following and it will be stored in a separate XML File titled SalesPeople.xml:

<divre name="code" class="xml"></divre><SalesPeople> <SalesPerson> <FirstName>Stephen</FirstName> <LastName>Jiang</LastName> <JobTitle>Sales Representative</JobTitle> <City>Redmond</City> <State>Washington</State> <PostalCode>98052</PostalCode> <SalesYTD>677588.46</SalesYTD> <SalesLastYear>22134322.42</SalesLastYear> </SalesPerson> <SalesPerson> <FirstName>Michael</FirstName> <LastName>Blythe</LastName> <JobTitle>Sales Representative</JobTitle> <City>Detroit</City> <State>Michigan</State> <PostalCode>48226</PostalCode> <SalesYTD>4557045.04</SalesYTD> <SalesLastYear>1740406.47</SalesLastYear> </SalesPerson> </SalesPeople> <divre></divre> <divre></divre>

XML in our Application

Next, we need to set this data up for use inside our application. In the case of this sample,
I’ve set our XamDataGrid into a GridPanel and set the DataContext of that grid to point at our XML Data. We’ll set the source property of the XMLDataProvider equal to the file location in this case in a folder titled Data. Then we’ll set the XPath to point to our SalesPersons. This will look something like this:

 

<divre name="code" class="xml"></divre><Grid.DataContext> <XmlDataProvider Source="Data/SalesPerson.xml XPath="/SalesPeople/SalesPerson" /> </Grid.DataContext> <divre></divre> <divre></divre>

 

Initial Binding to the XamDataGrid

Next, using simple WPF Binding, we can bind the xml file to the XamDataGrid:

<divre name="code" class="xml"></divre><igDP:XamDataGrid x:Name="xamDataGrid1" DataSource="{Binding}" /> <divre></divre> <divre></divre>

Customizing Field Settings

Lastly, we may want to do something like enable Summaries on the xamDataGrid and will notice that everything is being picked up as a string. To get around this we can format our data as the appropriate type by adding the Fields and associating the appropriate types to those fields. Note: We can also format the field’s labels to achieve something like “First Name” rather than “FirstName.”

<divre name="code" class="xml"></divre><igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.FieldSettings> <igDP:FieldSettings AllowSummaries="True" SummaryUIType="MultiSelect" /> </igDP:FieldLayout.FieldSettings> <igDP:FieldLayout.Fields> <igDP:Field Name="FirstName" Label="First Name" /> <igDP:Field Name="LastName" Label="Last Name" /> … <igDP:Field Name="SalesYTD" Label="Sales YTD"> <igDP:Field.Settings> <igDP:FieldSettings EditAsType="{x:Type sys:Double}" /> </igDP:Field.Settings> </igDP:Field> … </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> <divre></divre> <divre></divre>

 

 

 

After this our data is all set up and ready to go. We have successfully bound our grid to an XML File.

  • databinding
  • WPF
  • XamDataGrid
  • Share
  • History
  • More
  • Cancel
Related
Recommended