• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 662
  • Last Modified:

How do I bind a combobox to an XML item attribute

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
sbooth1117
Asked:
sbooth1117
  • 2
1 Solution
 
alainbrydenCommented:
Have you not tried

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

?
0
 
sbooth1117Author Commented:
I thought that as well. I tried again and it still didn't work.
0
 
sbooth1117Author Commented:
DisplayMemberPath="@name" is what worked.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now