-
January 20th, 2010, 03:11 AM
#1
Binding ComboBox to XML data. Having a problem.
Folks,
I was able to bind my ComboBox to an XML file, but there’s a “small cosmetic” problem. The data in the XML file looks like this:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<Options>
<BaudRates>
<BaudRate>4800</BaudRate>
<BaudRate>9600</BaudRate>
<BaudRate>19200</BaudRate>
</BaudRates>
</Options>
But the ComboBox displays it all in one item: 4800960019200
The binding is done entirely in XAML:
Code:
<ComboBox Name="cboBaudRate" Grid.Column="1" Grid.Row="1" Margin="0,2,0,0" HorizontalAlignment="Left" Width="72" Height="20" VerticalAlignment="Top" >
<ComboBox.ItemsSource>
<Binding Source="{StaticResource SerialPortOptions}" XPath="./BaudRates" />
</ComboBox.ItemsSource>
</ComboBox>
How can I display each XML item as a separate ComboBox item?
Of course, I can post more snippets if needed.
Thanks,
- Nick
-
January 20th, 2010, 09:02 AM
#2
Re: Binding ComboBox to XML data. Having a problem.
You need to select the individual item node in your XPath expression, like this:
Code:
<ComboBox.ItemsSource>
<Binding Source="{StaticResource SerialPortOptions}" XPath="./BaudRates/BaudRate" />
</ComboBox.ItemsSource>
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|