コード例 #1
0
 /// <summary>
 /// 调取天气方法
 /// </summary>
 private void GetWeatherData()
 {
     Task.Factory.StartNew(() =>
     {
         string now   = "https://api.thinkpage.cn/v3/weather/now.json?key={0}&location={1}&language=zh-Hans&unit={2}";                  //实时天气
         string daily = "https://api.thinkpage.cn/v3/weather/daily.json?key={0}&location={1}&language=zh-Hans&unit={2}&start=0&days=5"; //历史天气
         now          = String.Format(now, Key, City, DegreeFormat.ToString());
         daily        = String.Format(daily, Key, City, DegreeFormat.ToString());
         Now          = WeatherManager.Instance.GetWeatherDataNow(now, City);
         DailyModel   = WeatherManager.Instance.GetWeatherDataDaily(daily, City);
         WeatherManager.Instance.WriteWeatherHistory(Now, DailyModel);
         DispatcherHelper.CheckBeginInvokeOnUI(
             () =>
         {
             if (Now != null)
             {
                 ResultCity    = Now.Results[0].Location.Name;
                 ResultDegree  = Now.Results[0].Now.Temperature;
                 ResultWeather = Now.Results[0].Now.Text;
                 IconPath      =
                     new Uri(
                         String.Format(AppDomain.CurrentDomain.BaseDirectory + "/Resources/MainWeatherImages/{0}.png",
                                       Now.Results[0].Now.Code), UriKind.RelativeOrAbsolute);
                 WeatherIcon = new BitmapImage(IconPath);
             }
         });
     }).ContinueWith(result =>
     {
         if (result.IsFaulted)
         {
             LogWriter.Instance.Error(result.Exception);
         }
     });
 }
コード例 #2
0
        /// <summary>
        /// 回调需要查询的城市
        /// </summary>
        /// <param name="searchResult"></param>
        /// <param name="degreeFormat"></param>
        private void SearchCity(string searchResult, string degreeFormat)
        {
            City         = searchResult;
            DegreeFormat = (Degree)Enum.Parse(typeof(Degree), degreeFormat);
            GetWeatherData();
            WeatherModel model = new WeatherModel();

            model.City         = City;
            model.DegreeFormat = DegreeFormat.ToString();
            DataManager.Instance.UpdateTables(model);
        }
コード例 #3
0
 private void LoadedChecked(Grid element)
 {
     foreach (var item in element.Children)
     {
         if (item is RadioButton)
         {
             if ((item as RadioButton).Content.ToString().ToLower().Contains(DegreeFormat.ToString()))
             {
                 (item as RadioButton).Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ffffff"));
             }
         }
     }
 }
コード例 #4
0
 /// <summary>
 /// 查询城市
 /// </summary>
 /// <param name="searchResult"></param>
 private void SearchCity(string searchResult)
 {
     SearchResult(searchResult, DegreeFormat.ToString());
 }