Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF XML Databind to ComboBox
    primarykey
    data
    text
    <p>HI All,</p> <p>I am trying to bind some XML into a combobox using the below code:</p> <pre><code> &lt;UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="myComboBoxControl"&gt; &lt;UserControl.Resources&gt; &lt;DataTemplate x:Key="dataTemplateNode"&gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="Auto" MinWidth="20"/&gt; &lt;ColumnDefinition Width="*" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;TextBlock Text="{Binding XPath=@LCode}" Grid.Column="0" Margin="5,0,0,0" FontWeight="Bold"/&gt; &lt;TextBlock Text="{Binding XPath=.}" Grid.Column="1"/&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;XmlDataProvider x:Key="xmlNodeList" Source="/data/LocationCodes.xml" XPath="/LocationCodes/Location"/&gt; &lt;/UserControl.Resources&gt; &lt;ComboBox Name="LocationCombo" ItemsSource="{Binding Source={StaticResource xmlNodeList}}" ItemTemplate="{StaticResource dataTemplateNode}" SelectedValue="{Binding XPath=@LCode}" HorizontalContentAlignment="Stretch" Height="23" /&gt; &lt;/UserControl&gt; </code></pre> <p>The project builds fine and i can see the ComboBox populated as expected. however, when i try to get the selected value in the code-behind all i get is an empty/null string:</p> <pre><code>string compName = this.LocationCombo.SelectedValuePath.ToString(); MessageBox.Show(compName); </code></pre> <p>the xml file looks like below:</p> <pre><code>&lt;LocationCodes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; &lt;Location LCode="ABD1W"&gt;Aberdeen&lt;/Location&gt; &lt;Location LCode="ATH1W"&gt;Athens&lt;/Location&gt; &lt;/LocationCodes&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload