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 6337357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:14:22+00:00 2026-05-24T19:14:22+00:00

I have tried for several hours and searching on the net for examples on

  • 0

I have tried for several hours and searching on the net for examples on how to pull multiple elements with the same name however different attributes and binding those to my XAML in my app for wp7,

the easiest way for me to explain is to simply show you,

heres what I have so far

       public class Match
    {
        public string HomeTeam { get; set; }
        public string AwayTeam { get; set; }
        public string HomeScore { get; set; }
        public string AwayScore { get; set; }
        public string GoalsPlayer { get; set; }
        public string goal { get; set; }
        public string GoalsTime { get; set; }
        public string DismissalsPlayer { get; set; }
        public string DismissalsTime { get; set; }
        public string BookingPlayer { get; set; }
        public string BookingTime { get; set; }
        public string GameTime { get; set; }
    }

 void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        XElement element = XElement.Parse(e.Result);
        try
        {
            listBox2.ItemsSource = from item in element.Descendants("competition")
                                   from match in item.Elements("match").Where(arg => arg.Attribute("awayTeam").Value == team | arg.Attribute("homeTeam").Value == team)
                                   select new Match
                                   {
                                       HomeTeam = (string)match.Attribute("homeTeam"),
                                       AwayTeam = (string)match.Attribute("awayTeam"),
                                       HomeScore = (string)match.Attribute("homeTeamScore"),
                                       AwayScore = (string)match.Attribute("awayTeamScore"),
                                       GoalsPlayer = (string)match.Attribute("playerName"),
                                       GoalsTime = (string)match.Attribute("time"),
                                   };
        }
        catch (Exception ex)
        {
             Debug.WriteLine(ex.StackTrace);
        }

here is my XAML

<ListBox Name="listBox2" Grid.Row="0">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Name="teams" Orientation="Vertical">
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Margin="0,10,0,0" Foreground="White" HorizontalAlignment="Left" Text="{Binding HomeTeam}"/>
                                    <TextBlock Margin="10,10,30,0" Foreground="White" Text="{Binding HomeScore}" TextWrapping="Wrap" FontSize="20" />
                                    <TextBlock Margin="0,10,0,0" Foreground="White" HorizontalAlignment="Left" Text="{Binding AwayTeam}"/>
                                    <TextBlock Margin="10,10,30,0" Foreground="White" Text="{Binding AwayScore}" TextWrapping="Wrap" FontSize="20" />
                                </StackPanel>
                                <StackPanel Name="scores" Orientation="Horizontal">
                                    <TextBlock Margin="0,10,0,0" Foreground="White" Text="{Binding GoalsPlayer}" TextWrapping="Wrap" FontSize="20" />
                                    <TextBlock Margin="10,10,30,0" Foreground="White" Text="{Binding GoalsTime}" TextWrapping="Wrap" FontSize="20" />
                                </StackPanel>
                                <StackPanel Name="dismissals">
                                    <TextBlock Foreground="White" Text="{Binding DismissalsPlayer}" TextWrapping="Wrap" FontSize="20"/>
                                    <TextBlock Foreground="White" Text="{Binding DismissalsTime}" TextWrapping="Wrap" FontSize="20"/>
                                </StackPanel>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>

here is my XML

<match homeTeam="Arsenal" awayTeam="Liverpool" homeTeamScore="0" awayTeamScore="2">
<goal time="77:13" playerName="Aaron Ramsey" />
<goal time="89:57" playerName="Luis Suarez"/>
<dismissal time="69:59" playerName="Emmanuel Frimpong"/>
</match>

I understand that I will only get one entry on my Page for Goals, which would be the first goal element in my XML

how can I go about that and implement every

<goal ...>
<goal ...>

into my Datatemplate that currently only shows the first entry, another potential problem is I cannot guarantee how many goals there will be so I am a really unsure on how to go about it entirely

thanks

John

  • 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-24T19:14:22+00:00Added an answer on May 24, 2026 at 7:14 pm

    Should playerName even resolve on your match? Because that’s where you are resolving it in your XML query.

    Regardless, what you are looking for here is a sub-object that can be held in a list property of the Match object:

    listBox2.ItemsSource = from item in element.Descendants("competition")
                           from match in item.Elements("match")
                               .Where(arg => arg.Attribute("awayTeam").Value == team || 
                                             arg.Attribute("homeTeam").Value == team)
                           select new Match
                           {
                               HomeTeam = (string)match.Attribute("homeTeam"),
                               AwayTeam = (string)match.Attribute("awayTeam"),
                               HomeScore = (string)match.Attribute("homeTeamScore"),
                               AwayScore = (string)match.Attribute("awayTeamScore"),
                               Goals = match.Elements("goals").Select(ev => new MatchEvent
                               {
                                   Player = (string)ev.Attribute("playerName"),
                                   Time = (string)ev.Attribute("time")
                               }).ToList(),
                               Dismissals = match.Elements("dismissals").Select(ev => new MatchEvent
                               {
                                   Player = (string)ev.Attribute("playerName"),
                                   Time = (string)ev.Attribute("time")
                               }).ToList(),
                           };
    

    And the updated XAML:

    <ListBox Name="listBox2" Grid.Row="0">
        <ListBox.ItemTemplate>
            <DataTemplate>
                 <StackPanel Name="teams" Orientation="Vertical">
                 <StackPanel Orientation="Horizontal">
                      <TextBlock Margin="0,10,0,0" Foreground="White" HorizontalAlignment="Left" Text="{Binding HomeTeam}"/>
                      <TextBlock Margin="10,10,30,0" Foreground="White" Text="{Binding HomeScore}" TextWrapping="Wrap" FontSize="20" />
                      <TextBlock Margin="0,10,0,0" Foreground="White" HorizontalAlignment="Left" Text="{Binding AwayTeam}"/>
                      <TextBlock Margin="10,10,30,0" Foreground="White" Text="{Binding AwayScore}" TextWrapping="Wrap" FontSize="20" />
                  </StackPanel>
                  <ItemsControl ItemsSource="{Binding Goals}">
                      <ItemsControl.ItemTemplate>
                          <DataTemplate>
                              <StackPanel Name="scores" Orientation="Horizontal">
                                  <TextBlock Margin="0,10,0,0" Foreground="White" Text="{Binding Player}" TextWrapping="Wrap" FontSize="20" />
                                  <TextBlock Margin="10,10,30,0" Foreground="White" Text="{Binding Time}" TextWrapping="Wrap" FontSize="20" />
                              </StackPanel>
                          </DataTemplate>
                      </ItemsControl.ItemTemplate>
                  </ItemsControl>
    
                  <ItemsControl ItemsSource="{Binding Dismissals}">
                      <ItemsControl.ItemTemplate>
                          <DataTemplate>
                              <StackPanel Name="scores" Orientation="Horizontal">
                                  <TextBlock Margin="0,10,0,0" Foreground="White" Text="{Binding Player}" TextWrapping="Wrap" FontSize="20" />
                                  <TextBlock Margin="10,10,30,0" Foreground="White" Text="{Binding Time}" TextWrapping="Wrap" FontSize="20" />
                              </StackPanel>
                          </DataTemplate>
                      </ItemsControl.ItemTemplate>
                  </ItemsControl>
              </StackPanel>
          </DataTemplate>
      </ListBox.ItemTemplate>
    </ListBox>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have spent several hours on this, and tried various things. I can confirm
I have been searching for several hours now how to do this, but can't
I have tried several of the solutions I have seen out here, but am
I have tried several mySQL queries to compare a column of dates stored as
I have tried several things so far, but I haven't had much luck yet.
I have tried several ways to login to a website through java. I have
Here is what I have. I have tried several things but I can't figure
I am stumped by this one. I have tried several angles and some come
I really need advice on how to do the following. I have tried several
I am trying to load a URLRequest in UIWebview. I have tried with several

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.