private void LoadData() { this.recentDS = new LatestPostsDS(); this.recentDS.DataRequestError += TitleControl.DS_DataRequestError; this.recentDS.OnLoadMoreStarted += TitleControl.DS_OnLoadMoreStarted; this.recentDS.OnLoadMoreCompleted += TitleControl.DS_OnLoadMoreCompleted; this.gv_HomePosts.ItemsSource = recentDS; this.gv_SimplePosts.ItemsSource = recentDS; this.DataContext = this.recentDS; }
private async void LoadData() { // hide splash screen after 2 seconds //ThreadPoolTimer.CreateTimer(SplashTimeOut, new TimeSpan(0, 0, 2)); this.recentDS = new LatestPostsDS(); this.recentDS.DataRequestError += recentDS_DataRequestError; this.recentDS.OnLoadMoreStarted += newsDs_OnLoadMoreStarted; this.recentDS.OnLoadMoreCompleted += newsDs_OnLoadMoreCompleted; this.lv_HomePosts.ItemsSource = this.recentDS; this.tn_Home.DataContext = this.recentDS; await this.recentDS.LoadMoreItemsAsync(20); this.newsDs = new NewsDS(); this.newsDs.DataRequestError += recentDS_DataRequestError; //this.newsDs.OnLoadMoreStarted += newsDs_OnLoadMoreStarted; //this.newsDs.OnLoadMoreCompleted += newsDs_OnLoadMoreCompleted; this.lv_News.ItemsSource = this.newsDs; this.tn_News.DataContext = this.newsDs; await this.newsDs.LoadMoreItemsAsync(20); this.listColumn = await DataHelper.Function.PostHelper.GetColumns(); this.lv_Column.ItemsSource = this.listColumn; this.tn_Column.DataContext = this.listColumn; await FavoriteCategoryDS.Instance.LoadData(); this.fgc_Category.DataContext = FavoriteCategoryDS.Instance; this.lv_category.ItemsSource = FavoriteCategoryDS.Instance.Items; this.fg_Category = new FavoriteGroup(this.lv_category); await FavoriteAuthorDS.Instance.LoadData(); this.fgc_Author.DataContext = FavoriteAuthorDS.Instance; this.lv_author.ItemsSource = FavoriteAuthorDS.Instance.Items; this.fg_Author = new FavoriteGroup(this.lv_author); this.lv_blog.ItemsSource = FavoritePostDS.Instance; await FavoritePostDS.Instance.LoadMoreItemsAsync(20); this.fgc_Post.DataContext = FavoritePostDS.Instance; this.fg_Blog = new FavoriteGroup(this.lv_blog); // check updates for first time var updateTasks = new List<Task>(2); updateTasks.Add(FavoriteAuthorDS.Instance.CheckUpdateForAll()); updateTasks.Add(FavoriteCategoryDS.Instance.CheckUpdateForAll()); //this.recentDS_OnLoadMoreCompleted(20); // we do not need to wait for the result, let's update UI when the tasks finished await Task.Run(async () => { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () => { await FavoriteAuthorDS.Instance.CheckUpdateForAll(); await FavoriteCategoryDS.Instance.CheckUpdateForAll(); }); }); // with DispatcherTimer, we can update UI without using Dispatcher.RunAsync var timer = new DispatcherTimer(); //check for update every 15 mins timer.Interval = TimeSpan.FromMinutes(15); timer.Tick += timer_Tick; // start the timer timer.Start(); FunctionHelper.Functions.RefreshUIOnDataLoaded(this.pb_Top, this.cmdBar); }