/// <summary> /// 加载主界面 /// </summary> /// <param name="element"></param> private void ViewBox(Grid element) { try { DispatcherHelper.CheckBeginInvokeOnUI( () => { //获取历史天气 WeatherDataModel[] objects = WeatherManager.Instance.ReadWeatherHistory(); if (objects != null) { Now = objects[0]; DailyModel = objects[1]; 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); } } else { IconPath = new Uri(AppDomain.CurrentDomain.BaseDirectory + "/Resources/MainWeatherImages/99.png", UriKind.RelativeOrAbsolute); WeatherIcon = new BitmapImage(IconPath); } }); view_Box = element.Children[0] as Decorator; WeatherModel model = new WeatherModel(); DataTable table = DataManager.Instance.SelectTables(model); if (table != null && table.Rows.Count > 0) { model.FetchData(table.Rows[0]); FetchData(model); GetWeatherData(); } else { WeatherIcon = new BitmapImage(IconPath); } } catch (Exception e) { MessageBox.Show(e.ToString()); LogWriter.Instance.Error(e); } }