我正在开发 Windows 应用商店应用程序。我有这样的 XML:
<?xml version="1.0" encoding="utf-8" ?>
<music>
<singer>
<name>Coldplay</name>
<song>Scientist</song>
<lyrics>lol lalala</lyrics>
</singer>
<singer>
<name>Coldplay</name>
<song>test2</song>
<lyrics>lol lalala2</lyrics>
</singer>
<singer>
<name>another</name>
<song>şarkı</song>
<lyrics>lol lalala3</lyrics>
</singer>
</music>
在 C# 代码中,“lvSingers”是我的列表视图。我在那里绑定了歌手的名字。
private void Page_Loaded(object sender, RoutedEventArgs e)
{
string musicXMLPath = Path.Combine(Package.Current.InstalledLocation.Path, "Assets/test.xml");
XDocument loadedData = XDocument.Load(musicXMLPath);
var data = from query in loadedData.Descendants("singer")
select new Singer
{
name = (string)query.Element("name"),
song = (string)query.Element("song"),
akor = (string)query.Element("lyrics")
};
lvSingers.ItemsSource = data;
}
}
当我运行这段代码时,我得到了多个歌手的名字,我想避免这种情况。例子:
Coldplay
Coldplay
another
我只想在那里只有一个酷玩乐队。我想要的只是不同的输出。感谢您的反馈和帮助。问候...