Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6172661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:25:57+00:00 2026-05-23T23:25:57+00:00

I have a XML file that i’m going to use as a database for

  • 0

I have a XML file that i’m going to use as a database for my project, this is the xml file i have:

http://pastebin.com/JgyYkn4E

I found this question and tryed it:
How to bind xml to the WPF DataGrid correctly?

I want to display Cadeiras of each Semestre, separately, one in each DataGrid. Changed some minors things to fit my project but it didn’t worked, after spending some hours i manage to put it working querying the XElement with this:

XElement db = XElement.Load("db.xml");
var cadeira = from elem in db.Descendants("Semestre")
              where elem.Element("Nome").Value == "Semestre 1"
              select elem.Element("Cadeiras");
dataGrid1.DataContext = cadeira;

First Question: This worked but i just want to know if this is the best thing to do because, this DataGrid is inside a TabItem (which is inside a TabControl), later i will have to create new TabItems (for each Semestre, with a DataGrid inside with Cadeiras of that respective Semestre) at runtime, without having the XAML binding aid.

Second Question: In XAML, what’s the difference between binding as in here How to bind xml to the WPF DataGrid correctly? and binding as this WPF Datagrid binding to xml ?

Thanks in advance.

Best regards,

-N

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:25:57+00:00Added an answer on May 23, 2026 at 11:25 pm

    You can do a lot via data templating, try this example in a XAML-Parser:

    <Page
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:sys="clr-namespace:System;assembly=mscorlib">
      <Page.Resources>
        <XmlDataProvider x:Key="data" XPath="GPA/Semestre" Source="http://pastebin.com/raw.php?i=JgyYkn4E"/>
      </Page.Resources>
      <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
          <TabControl ItemsSource="{Binding Source={StaticResource data}}">
            <TabControl.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding XPath=Nome}"/>
                </DataTemplate>
            </TabControl.ItemTemplate>
            <TabControl.ContentTemplate>
                <DataTemplate>
                    <DataGrid ItemsSource="{Binding XPath=Cadeiras/Cadeira}" AutoGenerateColumns="False">
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="Activa" Binding="{Binding XPath=Activa}"/>
                            <DataGridTextColumn Header="Nome" Binding="{Binding XPath=Nome}"/>
                            <DataGridTextColumn Header="Nota" Binding="{Binding XPath=Nota}"/>
                        </DataGrid.Columns>
                    </DataGrid>
                </DataTemplate>
            </TabControl.ContentTemplate>
          </TabControl>
      </ScrollViewer>
    </Page>
    

    This will create the TabControl and all the DataGrids for you. (In your sample the Cadeiras do not look very complex so each of them are just one row in a DataGrid, if you need one DataGrid per Cadeira you can do that as well by creating an ItemsControl whose ItemTemplate is a DataGrid)


    The difference between the methods in those questions is that they use different classes to represent the XML, normally you would not use XElement since that will not support XPath in the bindings.

    LINQ to XML objects XDocument and XElement do not use XPath. For details, see How to: Bind to XDocument, XElement, or LINQ for XML Query Results.


    There is no inherently correct way to do this but as there is native binding support for XmlDataProviders and thus XmlDocuments i would go with that unless i have a significant reason not to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file that looks like: <results> <result> <title>Welcome+to+The+JASON+Project%21</title> <url>http%3A%2F%2Fwww.jason.org%2F</url> <domain />
I have an XML file that starts like this: <Elements name=Entities xmlns=XS-GenerationToolElements> I'll have
I have an XML file that looks like this. <collections id=my collections> <category id=my
I have an .xml file that is going to be shipped within my app.
I have an xml file that I need to load. This xml file holds
I have an xml file that is a project resource. I can access it
I have an xml file that looks like this; <Employee> <EmployeeName>Burt Reynolds</EmployeeName> <EmployeeTitle>Bad Ass</EmployeeTitle>
I have an XML file that's structured like this: <foo> <bar></bar> <bar></bar> ... </foo>
I have an xml file that looks like this: ... <e1> <e2> <e3>content1.1</e3> <e3>content1.2</e3>
I have an XML file that looks like this <library> <book> <title>Title</title> <author>author</author> <price>20</price>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.