Solved

How do I bind a combobox to an XML item attribute

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

In my page resource section I have:
<Page.Resources>
        <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.
0
Comment
Question by:sbooth1117
  • 2
3 Comments
 
LVL 20

Expert Comment

by:alainbryden
ID: 33570805
Have you not tried

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

?
0
 

Author Comment

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

Accepted Solution

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

910 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now