/
MainPage.xaml.cs
80 lines (72 loc) · 2.87 KB
/
MainPage.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Media.Imaging;
using System.IO.IsolatedStorage;
namespace Weather
{
public partial class MainPage : PhoneApplicationPage
{
//创建数组存放天气信息
List<CityWeatherInfo> citys = new List<CityWeatherInfo>();
public MainPage()
{
InitializeComponent();
citys = IsolatedStorageSettings.ApplicationSettings["City"] as List<CityWeatherInfo>;
BingUI();
}
private void BingUI()
{
string DayOrNight;
int hour = DateTime.Now.Hour;
ImageBrush img = new ImageBrush();
DayOrNight = TimeTools.GetDayorNight();
img.ImageSource = new BitmapImage(new Uri("/Images/Back/" + DayOrNight + ".jpg", UriKind.RelativeOrAbsolute));
LayoutRoot.Background = img;
foreach (var item in citys)
{
AddCity(item.CityName, item.TodayLow + "℃~" + item.TodayHight + "℃", "/Images/Forecasts/" + DayOrNight + "/" + item.TodayIcon + ".png");
}
}
private void ApplicationBarIconButton_Click(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/CityListEdit.xaml", UriKind.RelativeOrAbsolute));
}
private void AddCity(string cityName, string cityTemperature, string WeatherIconPath)
{
CityTileData cityData = new CityTileData();
cityData.cityTemperature = cityTemperature;
cityData.cityWeatherIcon = WeatherIconPath;
CityTile city = new CityTile();
city.DataContext = cityData;
city.cityName.Content = cityName;
city.Width = 184;
city.Height = 105;
city.Margin = new Thickness(15, 10, 15, 10);
wrapPanelCityList.Children.Add(city);
city.cityName.Click += new RoutedEventHandler(cityName_Click);
}
void cityName_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Loading.xaml?cityName=" + ((Button)sender).Content + "&AndGoPage=WeatherView", UriKind.RelativeOrAbsolute));
}
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
if (MessageBox.Show("", "确定要退出程序吗", MessageBoxButton.OKCancel)==MessageBoxResult.OK)
{
App.Quit();
}
base.OnBackKeyPress(e);
}
}
}