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

  • Home
  • SEARCH
  • 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 9016657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:03:19+00:00 2026-06-16T04:03:19+00:00

I want to group my xml binded datagrid… This code I’ve got from the

  • 0

I want to group my xml binded datagrid…

This code I’ve got from the internet and worked !
But instead of binding DataContext to a list (addressList), I need to bind my XML file here…
How do I do that ?

        addressList = new ObservableCollection<Address>(){   <== this is an example ! But I've got a XML file ?! Howto ?
            new Address{ Country="Argentina", City="Buenos Aires", Street="Ldiary"},
            new Address{ Country="Argentina", City="Buenos Aires", Street="Translations"},
            new Address{ Country="Austria", City="Graz", Street="Ldiary Translations"},
            new Address{ Country="Austria", City="Salzburg", Street="Ldiary"},
            new Address{ Country="Belgium", City="Bruxelles", Street="Translations"},
            new Address{ Country="Belgium", City="Charleroi", Street="Ldiary Translations"},
            new Address{ Country="Brazil", City="Campinas", Street="Japanese"},
            new Address{ Country="Brazil", City="Resende", Street="English"},
            new Address{ Country="Brazil", City="Rio de Janeiro", Street="Ldiary Translations"},
            new Address{ Country="Canada", City="Montreal", Street="Ldiary Translations"},
            new Address{ Country="Canada", City="Montreal", Street="Ldiary Translations"},
            new Address{ Country="Denmark", City="Arhus", Street="English to Japanese"},
            new Address{ Country="Denmark", City="Kobenhavn", Street="Ldiary Translations"},
            new Address{ Country="Finland", City="Helsinki", Street="Ldiary Translations"},
            new Address{ Country="Finland", City="Oulu", Street="Ldiary Translations"},
            new Address{ Country="France", City="Lille", Street="Ldiary Translations"},
            new Address{ Country="France", City="Lyon", Street="Ldiary Translations"},
            new Address{ Country="France", City="Marseille", Street="Ldiary Translations"},
            new Address{ Country="France", City="Nantes", Street="English"},
            new Address{ Country="Germany", City="Aachen", Street="Japanese"},
            new Address{ Country="Germany", City="Berlin", Street="Ldiary Translations"}
        };

this.DataContext = addressList; <= Not 
CollectionView cv = CollectionViewSource.GetDefaultView(dataGrid.DataContext) as  CollectionView;
        cv.GroupDescriptions.Add(new PropertyGroupDescription("Country"));

MY XAML:

 <Window.Resources>
    <XmlDataProvider x:Key="SmsData" XPath="/response"> => source added by code

    </XmlDataProvider>

    <local:RowColorConverter x:Key="RowColorConverter" />
</Window.Resources>
<Grid>

    <DataGrid ItemsSource="{Binding Source={StaticResource SmsData}, XPath=conv/sms}" AutoGenerateColumns="False" Name="dataGrid1" GridLinesVisibility="None" IsReadOnly="True" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto" Margin="-5,13,4,244" BorderThickness="0" UseLayoutRounding="False" IsEnabled="True" SelectionChanged="dataGrid1_SelectionChanged">

        <DataGrid.GroupStyle>
            <GroupStyle AlternationCount="6" >
                <GroupStyle.ContainerStyle>
                    <Style TargetType="{x:Type GroupItem}">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate>
                                    <ItemsPresenter />
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </GroupStyle.ContainerStyle>
            </GroupStyle>
        </DataGrid.GroupStyle>
        <DataGrid.RowStyle>
            <Style>
                <Setter Property="DataGridRow.Background" 
                        Value="{Binding RelativeSource={RelativeSource AncestorType=GroupItem}, 
                    Path=(ItemsControl.AlternationIndex), Converter={StaticResource RowColorConverter}}"/>
            </Style>
        </DataGrid.RowStyle>
        <DataGrid.Columns>

            <DataGridTextColumn Binding="{Binding XPath=msgid}" Width="100"  />
            <DataGridTextColumn Binding="{Binding XPath=imsgid}" Width="100"  />
            <DataGridTextColumn Binding="{Binding XPath=recipient}" Width="100"  />
            <DataGridTextColumn Binding="{Binding XPath=datetime}" Width="120" />
            <DataGridTextColumn Binding="{Binding XPath=message}" Width="225" />
        </DataGrid.Columns>
    </DataGrid>
</Grid>

in cs (field msgid is element to group on):

XmlDataProvider dataProvider = this.FindResource("SmsData") as XmlDataProvider;
            dataProvider.Source = new Uri(someurl);

DataContext = this;
        CollectionView cv = CollectionViewSource.GetDefaultView(dataGrid1.DataContext) as CollectionView;
        cv.GroupDescriptions.Add(new PropertyGroupDescription("msgid"));

my xml file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<response>
    <conv>
        <sms><recipient>test</recipient><datetime/><message/></sms>
        <sms>
            <msgid>123456</msgid>
            <datetime>15-12-2012 21:36:55</datetime>
            <message>test</message>
        </sms>
    </conv>
</response>
  • 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-06-16T04:03:20+00:00Added an answer on June 16, 2026 at 4:03 am

    You can bind XML data directly in the Xaml.

    Example:

    Create an xml source from your file in your Window or Control resources

     <Window.Resources>
         <XmlDataProvider x:Key="AddressXML" XPath="/Address" Source="C:\AddressData.xml" />
     </Window.Resources>
    

    Then you can bind to elements/Nodes in you document to your DataGrid or other controls.

      <Grid>
          <DataGrid DataContext="{StaticResource AddressXML}" ItemsSource="{Binding XPath=Address}" />
      </Grid>
    

    If you post an example of your xml file I can give you a better explanation

    CollectionViewSource in xaml

       xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
       xmlns:dat="clr-namespace:System.Windows.Data;assembly=PresentationFramework"
    
    
    <Window.Resources>
        <XmlDataProvider x:Key="SmsData" XPath="/response" Source="C:\data.xml"/>
    
        <CollectionViewSource x:Key="SmsView"  Source="{StaticResource SmsData}">
            <CollectionViewSource.SortDescriptions>
                <scm:SortDescription PropertyName="datetime" />
            </CollectionViewSource.SortDescriptions>
            <CollectionViewSource.GroupDescriptions>
                <dat:PropertyGroupDescription PropertyName="msgid" />
            </CollectionViewSource.GroupDescriptions>
        </CollectionViewSource>
    
    </Window.Resources>
    
    <Grid>
        <DataGrid DataContext="{StaticResource SmsView}"  ItemsSource="{Binding XPath=conv/sms}" AutoGenerateColumns="False" >
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding XPath=msgid}" Width="100"  />
                <DataGridTextColumn Binding="{Binding XPath=imsgid}" Width="100"  />
                <DataGridTextColumn Binding="{Binding XPath=recipient}" Width="100"  />
                <DataGridTextColumn Binding="{Binding XPath=datetime}" Width="120" />
                <DataGridTextColumn Binding="{Binding XPath=message}" Width="225" />
            </DataGrid.Columns>
    
        </DataGrid>
    </Grid>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am displaying in a group tableview contents parsed from XML. I want to
The XML file I want to extract data from looks as below: `<groups> <group>approved</group>
Im making a group table that is populated from an XML/RSS feed, ive managed
I am having following xml.What i need to do is,i want to group rows
I want to transform this XML to create pages of tags as my XSLT
Let's say I have some XML like this: <group> <request> <field id=a/> <field id=b/>
I want to create a xml file from the data given by the users.
i have a XML datadump from a database that i want to present using
In wp7 i want to parse xml tag .Xml : <top> <value name=Group A>
I just want to group 4 buttons like this... Portrait mode: [1][2] [3][4] Landscape

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.