0
是否可以解釋並更正下列給定XML
文件的XAML以定義ComboBox ItemsSource
?定義DataContext
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>
在ItemsSo的XPath中,前面斜線的用途是什麼urce屬性? – sammarcow
它選擇該類型的節點,而不管它們在樹中的哪個位置。由於ComboItems在DBConnection下,因此您可以使用它或指定「DBConnection/ComboItem」作爲查詢 –
以下是有關XPath語法的資源 http://www.w3schools.com/xpath/xpath_syntax.asp –