当前位置:编程学习 > wap >>

wp7天气预报源代码(一)

先上效果图

在这里更正一下,黑天的天气预报界面截图的时候,当时操作系统的时间是错误的,导致模拟器里显示2008年。
天气预报是我学WindowsPhone7以来的第一个作品。用的是谷歌的api。功能一个下午就写完了,还是这个界面的设计加P图费了我不少的时间。这个应用已经通过了微软的审核。
下载地址:http://115.com/file/e7b668w9#
Weather.xap
有什么问题请联系QQ:29992379
由于界面过于复杂,为了实现高效的重用性,我使用了用户自定义控件。通过后台对象的实例化生成的界面。没有办法把所有的代码都展现出来。
   1:  // 应用程序启动(例如,从“开始”菜单启动)时执行的代码
   2:          // 此代码在重新激活应用程序时不执行
   3:          private void Application_Launching(object sender, LaunchingEventArgs e)
   4:          {
   5:              if (!IsolatedStorageSettings.ApplicationSettings.Contains("City"))
   6:              {
   7:                  List<CityWeatherInfo> citys = new List<CityWeatherInfo>();
   8:                  IsolatedStorageSettings.ApplicationSettings["City"] = citys;
   9:                  IsolatedStorageSettings.ApplicationSettings.Save();
  10:              }
  11:          }
   1:  List<CityWeatherInfo> citys = new List<CityWeatherInfo>();
我使用的是IsolatedStorageSettings.ApplicationSettings存储的城市信息。下面为添加城市信息的代码。
   1:  //添加城市
   2:          private void AddCityButton_Click(object sender, RoutedEventArgs e)
   3:          {
   4:             
   5:              if ((citys.Where(list => list.CityName == CityNameTextBox.Text).ToList()).Count == 0)
   6:              {
   7:                  citys.Add(new CityWeatherInfo() { CityGuid = Guid.NewGuid().ToString(), CityName = CityNameTextBox.Text });
   8:                  IsolatedStorageSettings.ApplicationSettings["City"] = citys;
   9:                  IsolatedStorageSettings.ApplicationSettings.Save();
  10:              }
  11:              IsolatedStorageSettings.ApplicationSettings["City"] = citys;
  12:              IsolatedStorageSettings.ApplicationSettings.Save();
  13:              NavigationService.Navigate(new Uri("/Loading.xaml?cityName=" + CityNameTextBox.Text+"&AndGoPage=MainPage", UriKind.RelativeOrAbsolute));
  14:          }
 
   1:  //删除城市
   2:          private void linkButtonDel_Click(object sender, RoutedEventArgs e)
   3:          {
   4:              for (int i = 0; i < citys.Count; i++)
   5:              {
   6:                  if (citys[i].CityGuid == ((HyperlinkButton)sender).Tag.ToString())
   7:                  {
   8:                      citys.RemoveAt(i);
   9:                  }
  10:              }
  11:              IsolatedStorageSettings.ApplicationSettings["City"] = citys;
  12:              IsolatedStorageSettings.ApplicationSettings.Save();
  13:              BindData();
  14:          }
先上获取天气信息的代码,我自己写了个获取谷歌天气信息的工具类,生成了DLL然后引用进来使用的。

  image


 

给城市赋天气信息
   1:   public partial class Loading : PhoneApplicationPage
   2:      {
   3:          List<CityWeatherInfo> citys = new List<CityWeatherInfo>();
   4:          WebClient client = new WebClient();
   5:          string cityName = "济南";
   6:          public Loading()
   7:          {
   8:              InitializeComponent();
   9:              citys = IsolatedStorageSettings.ApplicationSettings["City"] as List<CityWeatherInfo>;
  10:          }
  11:      &

补充:移动开发 , Windows Phone ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,