How do I bind a combobox to an XML item attribute

Posted on 2010-08-31
Medium Priority
Last Modified: 2013-11-12
Here is the XML:
<?xml version="1.0" encoding="utf-8" ?>
      <state name="ALABAMA" abbreviation="AL" />
      <state name="ALASKA" abbreviation="AK" />

In my page resource section I have:
        <XmlDataProvider x:Key="StateData" Source="xmlData\states.xml" XPath="states/state" />

My control looks like this:
<ComboBox Name="cbxState" ItemsSource="{Binding Source={StaticResource StateData}}"  />

I can see that my combobox is being filled with all the states, but I can't seem to get it to bind to the name attribute.  So my question is how do I get the combobox to list the name attributes associated with the states?

Thank you for your help.
Question by:sbooth1117
  • 2
LVL 21

Expert Comment

ID: 33570805
Have you not tried

<ComboBox Name="cbxState" ItemsSource="{Binding Source={StaticResource StateData}, Path=name}"  />


Author Comment

ID: 33571081
I thought that as well. I tried again and it still didn't work.

Accepted Solution

sbooth1117 earned 0 total points
ID: 33572450
DisplayMemberPath="@name" is what worked.

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
When you have multiple client accounts to manage, it often feels like there aren’t enough hours in the day. With too many applications to juggle, you can’t focus on your clients, much less your growing to-do list. But that doesn’t have to be the cas…

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question