Click here to Skip to main content
15,941,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
            <XmlDataProvider x:Name="MyData" Source="MyData.xml" XPath="Contacts/Contact" />

I am having the hardest time finding a way to sort the incoming data from XmlDataProvider. The field <company> is going to a ComboBox and needs to be sorted from A to Z. Can someone please help?

1 solution

Several sources mention using CollectionViewSource ([^])
       <XmlDataProvider x:Key="xmlData" Source="MyData.xml" XPath="CustDB/Customer"/>

     <CollectionViewSource x:Name="dataCvs" Source="{Binding Source={StaticResource xmlData}}" />


To the code behind you add somewhere (some Loaded or Click event) the following:
     New SortDescription With {.PropertyName = "Name"})
     'PropertyName should be the tag in the XML file

However, it's simpler and more recommended to use Linq. Like you previously tried :) : Binding Text Box to Combo Box populated with LINQ to XML data[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900