试图为奥斯陆的祈祷时间创建一个祈祷时间应用程序。我在应用程序中有一个 XML 文件。我想做的事情:根据月份和日期,为早祷,晚祷等获得价值。
我一次想要一个值,并将其显示在文本块中。我该怎么做?我目前正在列表框中获取信息,但我更希望单个值显示在文本块中。还是我应该使用其他东西?
public class PrayerTime
{
public string Fajr { get; set; }
public string Sunrise { get; set; }
}
要获取值:
XDocument loadedCustomData = XDocument.Load("WimPrayerTime.xml");
var filteredData = from c in loadedCustomData.Descendants("PrayerTime")
where c.Attribute("Day").Value == myDay.Day.ToString()
&& c.Attribute("Moth").Value == myDay.Month.ToString()
select new PrayerTime()
{
Fajr = c.Attribute("Fajr").Value,
Soloppgang = c.Attribute("Soloppgang").Value,
};
listBox1.ItemsSource = filteredData;
我还想知道为此目的应该如何最好地设置 XML。
像这样:
<PrayerTime>
<Day>1</Day>
<Month>5</Month>
<Fajr>07:00</Fajr>
<Sunrise>09:00</Sunrise>
</PrayerTime>
或者像这样:
<PrayerTime
Day ="1"
Month="5"
Fajr="07:00"
Sunrise="09:00"
/>