Can some one explain and correct the following XAML given the XML File to define the ComboBox ItemsSource?
XAML:
<ComboBox Name="cbConnection" DataContext="{Binding Source=c:\temp\ConnectionList.xml, XPath=DBConnection}" ItemsSource="{Binding XPath=ComboItem}" DisplayMemberPath="Key" SelectedValuePath="Value">
c:\temp\ConnectionList.xml:
<?xml version="1.0" encoding="utf-8" ?>
<DBConnection>
<ComboItem>
<Key>Computer-A</Key>
<Value>Server=COMPA;Database=MyDB;Integrated Security=SSPI;</Value>
</ComboItem>
<ComboItem>
<Key>Computer-B</Key>
<Value>Server=COMPB\SQL2012STD;Database=MyDB;Integrated Security=SSPI;</Value>
</ComboItem>
</DBConnection>
You don’t necessarily need to fool around with the DataContext. Just set the ItemsSource appropriately.
and provide data to other WPF elements. ItemsSource should point to this provider.
Here is the XMLDataProvider, put this in a resource dictionary in your page:
Here is the corrected ComboBox:
Here is the corrected XML: