我嘗試通過Linq To XML將XML文件中的鏈接數據添加到我的WPF接口。下面,返回的錯誤和代碼:Linq XML問題和數據綁定
The type of the expression in the select clause is incorrect. Type inference failed in the call to 'Select'.
我的代碼
C#:
IEnumerable<string> datas = from d in XDocument.Load(@"Resources\limits.xml").Descendants("limits")
where (int)d.Element("ID") == id
select d.Elements;
XAML/WPF
<StackPanel>
<TextBlock Text="{Binding XPath=explicationTitle}" FontWeight="Bold" Margin="10" />
<TextBlock Text="{Binding XPath=explicationDescription}" Margin="10" />
<TextBlock Text="Aucune" FontWeight="Bold" Margin="10" />
<TextBlock Text="{Binding XPath=explicationLimiteAucune}" Margin="10" />
<TextBlock Text="Modérée" FontWeight="Bold" Margin="10" />
<TextBlock Text="{Binding XPath=explicationLimiteModeree}" Margin="10" />
<TextBlock Text="Totale" FontWeight="Bold" Margin="10" />
<TextBlock Text="{Binding XPath=explicationLimiteTotale}" Margin="10" />
</StackPanel>
XML數據文件:
<Limits xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Limit>
<Id>1</Id>
<title>Ma première limite :)</title>
<description>NFC West</description>
<explication>
information
de
bla blabla
</explication>
<explicationTitle>Poney</explicationTitle>
<explicationDescription>Description de la limitation</explicationDescription>
<explicationLimiteAucune>Aucune limite..tout va bien :)</explicationLimiteAucune>
<explicationLimiteModeree>Quelques soucis, rien de grave</explicationLimiteModeree>
<explicationLimiteTotale>Gros soucis :)</explicationLimiteTotale>
</Limit>
<Limit>
<Id>2</Id>
<title>Limitation 2</title>
<description>NFC West</description>
<explication>
information 2
de 2
bla blabla 2 2 2
</explication>
<explicationTitle>Poney</explicationTitle>
<explicationDescription>Description de la limitation</explicationDescription>
<explicationLimiteAucune>Aucune limite..tout va bien :)</explicationLimiteAucune>
<explicationLimiteModeree>Quelques soucis, rien de grave</explicationLimiteModeree>
<explicationLimiteTotale>Gros soucis :)</explicationLimiteTotale>
</Limit>
</Limits>
如何創建一個漂亮的LINQ到XML請求的數據綁定?