void load_MouseUp(object sender, MouseButtonEventArgs e) { LoadingMoreElement load = (LoadingMoreElement)sender; if (!load.isLoading) { load.changeToLoading(); subThread = new Thread(new ThreadStart(getMoreBook)); subThread.Start(); } }
private void getSearchResult() { try { _cursearch = ""; this.Dispatcher.Invoke(new Action(() => { _cursearch = this.searchBox.Text.Replace(" ", "+").Replace("+", "%2B"); })); BookList booklist = new BookList(); booklist.AddNewBook(_cursearch, _curpage); this.loadingLabel.Dispatcher.Invoke(new Action(() => { if (booklist.Count == 0) { this.loadingLabel.Content = "找不到相关图书"; this.loadingLabel.Visibility = Visibility.Visible; } else { this.loadingLabel.Visibility = Visibility.Hidden; } })); for (int i = 0; i < booklist.Count; i++) { this.searchResult.Dispatcher.Invoke(new Action(() => { BookElement be = new BookElement(booklist[i]); be.MouseUp += new MouseButtonEventHandler(be_MouseUp); be.downloadClicked += new RoutedEventHandler(downloadClicked); searchResult.Children.Add(be); })); } if (booklist.GetMoreable) { this.searchResult.Dispatcher.Invoke(new Action(() => { LoadingMoreElement load = new LoadingMoreElement(); load.MouseUp += new MouseButtonEventHandler(load_MouseUp); searchResult.Children.Add(load); })); } } catch { this.Dispatcher.Invoke(new Action(() => { this.loadingLabel.Content = "加载失败"; this.loadingLabel.Visibility = Visibility.Visible; })); } }
private void getMoreBook() { try { BookList booklist = new BookList(); booklist.AddNewBook(_cursearch, ++_curpage); for (int i = 0; i < booklist.Count; i++) { this.searchResult.Dispatcher.Invoke(new Action(() => { BookElement be = new BookElement(booklist[i]); be.MouseUp += new MouseButtonEventHandler(be_MouseUp); be.downloadClicked += new RoutedEventHandler(downloadClicked); int count = searchResult.Children.Count; searchResult.Children.Insert(count - 1, be); })); } this.searchResult.Dispatcher.Invoke(new Action(() => { int count = searchResult.Children.Count; LoadingMoreElement load = (LoadingMoreElement)searchResult.Children[count - 1]; load.changeToGetting(); if (!booklist.GetMoreable) { searchResult.Children.Remove(load); } })); } catch (Exception e) { if (e is ThreadAbortException) { return; } this.searchResult.Dispatcher.Invoke(new Action(() => { int count = searchResult.Children.Count; LoadingMoreElement load = (LoadingMoreElement)searchResult.Children[count - 1]; load.changeToFailed(); })); } }
private void getSearchResult() { try { _cursearch = ""; this.Dispatcher.Invoke(new Action(() => { _cursearch = this.searchBox.Text.Replace(" ", "+").Replace("+", "%2B"); })); BookList booklist = new BookList(); booklist.AddNewBook(_cursearch, _curpage); this.loadingLabel.Dispatcher.Invoke(new Action(() => { if (booklist.Count == 0) { this.loadingLabel.Content = "找不到相关图书"; this.loadingLabel.Visibility = Visibility.Visible; } else this.loadingLabel.Visibility = Visibility.Hidden; })); for (int i = 0; i < booklist.Count; i++) { this.searchResult.Dispatcher.Invoke(new Action(() => { BookElement be = new BookElement(booklist[i]); be.MouseUp += new MouseButtonEventHandler(be_MouseUp); be.downloadClicked += new RoutedEventHandler(downloadClicked); searchResult.Children.Add(be); })); } if (booklist.GetMoreable) { this.searchResult.Dispatcher.Invoke(new Action(() => { LoadingMoreElement load = new LoadingMoreElement(); load.MouseUp += new MouseButtonEventHandler(load_MouseUp); searchResult.Children.Add(load); })); } } catch { this.Dispatcher.Invoke(new Action(() => { this.loadingLabel.Content = "加载失败"; this.loadingLabel.Visibility = Visibility.Visible; })); } }