Solved

How do I bind a combobox to an XML item attribute

Posted on 2010-08-31
3
653 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
EF5: Question about Metadata Artifact Processing 4 22
PL SQL Developer 7 53
Getting error in connectionstring with Excel. 30 45
MailAddress in vb 4 29
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

861 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