Click here to Skip to main content
15,920,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a WPF application , where I need to bind the XML data to the ComboBox. Below code I have tried. But values are not not showing on the ComboBox. Anybody please helpme to solve this.

What I have tried:

This the Languages.xml File
<?xml version="1.0" encoding="utf-8" ?>
  <language name="English"/>
  <language name="Hindi"/>
  <language name="Odia"/>
  <language name="Telugu"/>
  <language name="Kannada"/>

And this is App.xaml
<Application x:Class="xmlBinding.App"
        <XmlDataProvider x:Key="XmlData" Source="Languages.xml"/>

And this MainWindow.xaml
<combobox x:name="cmbName" height="30" width="150" itemssource="{Binding Source={StaticResource XmlData},XPath=Languages/.}"
="" displaymemberpath="@name">
Updated 20-May-21 22:32pm
Chris Copeland 20-May-21 9:39am    
Have you checked in the Debug output window? Normally when there's an issue with XAML either loading or rendering a resource then it will print out a message accordingly.
Gita Padhihari 24-May-21 3:47am    
Thank you for the solution. The issue got resolved.
[no name] 20-May-21 13:19pm    
As a last resort, you can always create the "list" in code (hard-coded or deserialized xml). Doesn't look like that particular list will change much either.

1 solution

Did you have a look at the Debug Output Windows as suggested by Chris?

If you see a message like this
XmlDataProvider cannot load asynchronous document from Source because of load or parse error in XML stream. Uri:'Languages.xml' IOException:'System.IO.IOException: Cannot locate resource 'languages.xml'.
then the XML file cannot be found.

In this case you can try to assign a path like this:
<XmlDataProvider x:Key="XmlData" Source="c:\\Languages.xml" XPath="Languages"/>

Do not forget to copy the XML file to the specified path.
Share this answer
Gita Padhihari 24-May-21 3:46am    
Thanks for the solutions. Yes The issue got resolved.
TheRealSteveJudge 25-May-21 2:05am    
Thank you for your feedback!

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