Bind XML to listvaluews in ComboBox

Bind XML to listvaluews in ComboBox

stefan.palm
Advocate Advocate
461 Views
1 Reply
Message 1 of 2

Bind XML to listvaluews in ComboBox

stefan.palm
Advocate
Advocate

I am trying to bind an XML to display as list values in an combobox but the items in the combobox do not diplay properly, no text is visible but there seems to be items in the drop down list. 

 

 

 

I use this code to define the datasource

 

 <XmlDataProvider x:Key="TransDB" Source="C:\ProgramData\Autodesk\Vault 2016\Extensions\DataStandard\Cadcraft\LanguageTranslator\LanguageTranslations.xml"/>

 

 

And I use this code to define my combobox and to bind the listvalues to my XML data source.

 

<ComboBox Grid.Row="10" Grid.Column="1" IsEditable="True" ItemsSource="{Binding Source={StaticResource TransDB}, XPath=/TranslatorData/TranslationsEntries/TranslationsEntries/Translation}" DisplayMemberPath="@TranslationText" SelectedValuePath="@TranslationText" Text="{Binding Prop[Title].Value, UpdateSourceTrigger=PropertyChanged}"/>

 

 

I have attached the datasource XML. What am i missing, why does not the "TranslationText" attribute show up in the listvalues for the combobox?

 

 

Thanks

0 Likes
462 Views
1 Reply
Reply (1)
Message 2 of 2

marco.mirandola
Advocate
Advocate
Hi Stefan, if you see a the "highlighting" bar when you hover the mouse over the open combobox, that means hat items are loaded but just not displayed. so, let's say you move the mouse over the open combobox and you see the blue bar selecting different rows, then you are on a good path.

the combobox can just display text, and you put XML elements in the combobox. this is the reason why you see there are records in the combo, but those cannot be displayed.

you made it right by setting the DisplayMemberPath="@<YourXmlAttribute>", as this will tell the combobox which attribute of the selected XML element shall be displayed.

Now, in your DisplayMemberPath, you point to a child XML Node called TranslationText. That is not a XML attribute. It's a XML element that has an inner text. Therefore the DisplayMemberPath does not work.

If you add an attribute TranslationText to your Translation XML element, it will work.

If you still try to access the inner text of the XML element, then i need to make a test myself and see if and how this could be done.
with the attribute it works for sure, with the inner text, i need to investigate.

ciao, marco
coolOrange
www.coolorange.com
0 Likes