最近、C# を使用して Windows Phone 7 用の天気予報アプリケーションを作成しました。しかし、摂氏でしか温度を表示できませんが、摂氏または華氏のいずれかを選択するオプションがあるsettings.xamlページにボタンを作成したいと思います(現在、このためのボタンを作成していません。アプリは自動的に摂氏温度)。誰でもこれで私を助けることができますか??? お疲れ様でした。
以下は私がそれに使用したコードです-:
private void ForecastDownloaded(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Result == null || e.Error != null)
{
MessageBox.Show("Cannot load Weather Forecast!");
}
else
{
XDocument document = XDocument.Parse(e.Result);
var data1 = from query in document.Descendants("current_condition")
select new Forecast
{
observation_time = (string) query.Element("observation_time"),
temp_C = (string)query.Element("temp_C"),
temp_F = (string)query.Element("temp_F"),
weatherIconUrl = (string)query.Element("weatherIconUrl"),
weatherDesc = (string)query.Element("weatherDesc"),
humidity = (string)query.Element("humidity"),
windspeedMiles = (string)query.Element("windspeedMiles"),
windspeedKmph = (string)query.Element("windspeedKmph")
};
Forecast forecast = data1.ToList<Forecast>()[0];
var data2 = from query in document.Descendants("weather")
select new Forecast
{
date = (string)query.Element("date"),
tempMaxC = (string)query.Element("tempMaxC"),
tempMaxF = (string)query.Element("tempMaxF"),
tempMinC = (string)query.Element("tempMinC"),
tempMinF = (string)query.Element("tempMinF"),
weatherIconUrl = (string)query.Element("weatherIconUrl"),
};
List<Forecast> forecasts = data2.ToList<Forecast>();
for (int i = 0; i < forecasts.Count(); i++)
{
forecasts[i].date = DateTime.Parse(forecasts[i].date).ToString("dddd");
}
AddPanoramaItem(forecast,forecasts);
}
}
private void AddPanoramaItem(Forecast forecast, List<Forecast> forecasts)
{
PanoramaItemObject pio = new PanoramaItemObject();
pio.temperature = "Temperature: " + forecast.temp_C + " °C";
pio.observation_time = "Observ. Time: " + forecast.observation_time;
pio.windspeed = "Wind Speed: " + forecast.windspeedKmph + " Kmph";
pio.huminity = "Huminity: " + forecast.humidity + " %";
pio.weatherIconUrl = forecast.weatherIconUrl;
pio.forecasts = forecasts;
PanoramaItem panoramaItem = new PanoramaItem();
panoramaItem.Header = queries[query];
int index = queries[query].IndexOf(",");
if (index != -1) panoramaItem.Header =
queries[query].Substring(0, queries[query].IndexOf(","));
else panoramaItem.Header = queries[query];
panoramaItem.ContentTemplate =
(DataTemplate)Application.Current.Resources["ForecastTemplate"];
panoramaItem.Content = pio;
Panorama.Items.Add(panoramaItem);
query++;
if (query < queries.Count())
LoadForecast();
}