Solved

How do I bind a combobox to an XML item attribute

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

747 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

10 Experts available now in Live!

Get 1:1 Help Now