LazyListBoxHelper 动态分页
生活随笔
收集整理的這篇文章主要介紹了
LazyListBoxHelper 动态分页
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
最近整理電腦東西,雖然WP7已成過去式,記錄下吧,代碼是該別人的,增加委托傳值,如得到獲取數(shù)據(jù)的百分比等
正則抓取下廚房數(shù)據(jù)
下廚房正則 <span\s+itemprop="amount"> (?<title>.+?)</span><img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*> 圖片<div\s+class="g-recipe-intro"\s+itemprop="summary">(?<title>.+?)</div> 介紹<em\s+itemprop="name">(?<title>.+?)</em> 配料<div\s+class="g-recipe-steps"\s+itemprop="instructions">.+?<ol>.+?<li>(?<title>.+?)<br\s+class="clr"/> 第一步 <li>(?<title>.+?)<br\s+class="clr"/>.+?</li> 做法 <pre\s+class="g-recipe-tips\s+g-f14">(?<title>.+?)</pre> 小貼士豆果<span><a\s+href="/store/lists/c1t(?<url>.+?)">(?<title>.+?)</a></span> 菜系類型 <a\s+href="(?<Href>.+?)"\s+target="_blank"><img.+?src="(?<ImgUrl>.+?)"\s+alt="(?<Name>.+?)"></a>.+?<p>(?<Place>.+?)</p> 菜系詳細(xì) <h2>特色菜:</h2>.+?([<span>.+?</span>].+?)</div> 特色菜 <dt>電話:</dt>.+?<dd>(?<Phone>.+?)</dd>做法 <em>(?<num>.+?)</em>.+?<span>(?<title>.+?)</span>.+? <img\s+src="(?<src>.+?)" <em>(?<num>.+?)</em>(?<title>.+?)<br\s+class="clr"/> No Image 主料 itemprop="name"\s+title=.+?的做法">(?<title>.+?)<span\s+class="buy-price"> <a\s+href=.+?的做法"\s+itemprop="name">(?<title>.+?)</a>分頁
public delegate void LazyListBoxHelperDelegateHandler(object obj);public class LazyListBoxHelper{static public int _pageIndex=0;static public bool _isBusy=true;//用于保存ListBox的ScrollViewer對象的引用static private ScrollViewer _scrollViewer = null;//用于判斷是否已經(jīng)捕捉ScrollViewerstatic private bool _isHookedScrollEvents = false;static public event LazyListBoxHelperDelegateHandler EventLazyListBoxHelperDelegateHandler;public static void InitLazyBox(Control LazyBox){List<ScrollBar> scrollBarList = GetVisualChildCollection<ScrollBar>(LazyBox);foreach (ScrollBar scrollBar in scrollBarList){if (scrollBar.Orientation == System.Windows.Controls.Orientation.Horizontal){}else{scrollBar.ValueChanged += verticalScrollBar_ValueChanged;}}}#region 分頁調(diào)用方法/// <summary> /// 分頁 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void verticalScrollBar_ValueChanged(object sender, RoutedEventArgs e){ScrollBar scrollBar = (ScrollBar)sender;object valueObj = scrollBar.GetValue(ScrollBar.ValueProperty);object maxObj = scrollBar.GetValue(ScrollBar.MaximumProperty);if (valueObj != null && maxObj != null){double value = (double)valueObj;double max = (double)maxObj - 1.0;if (value >= max){if (EventLazyListBoxHelperDelegateHandler != null){EventLazyListBoxHelperDelegateHandler(max);}}}}public static List<T> GetVisualChildCollection<T>(object parent) where T : UIElement{List<T> visualCollection = new List<T>();GetVisualChildCollection(parent as DependencyObject, visualCollection);return visualCollection;}public static void GetVisualChildCollection<T>(DependencyObject parent, List<T> visualCollection) where T : UIElement{int count = VisualTreeHelper.GetChildrenCount(parent);for (int i = 0; i < count; i++){DependencyObject child = VisualTreeHelper.GetChild(parent, i);if (child is T){visualCollection.Add(child as T);}else if (child != null){GetVisualChildCollection(child, visualCollection);}}}#endregion/// <summary> ///獲取控件的子控件 /// </summary> /// <typeparam name="T">子控件類</typeparam> /// <param name="root">父控件</param> /// <returns></returns> public static T FindChildOfType<T>(DependencyObject root) where T : class{var queue = new Queue<DependencyObject>();queue.Enqueue(root);while (queue.Count > 0){DependencyObject current = queue.Dequeue();for (int i = VisualTreeHelper.GetChildrenCount(current) - 1; 0 <= i; i--){var child = VisualTreeHelper.GetChild(current, i);var typedChild = child as T;if (typedChild != null){return typedChild;}queue.Enqueue(child);}}return null;}/// <summary> /// 高敏感翻頁 /// </summary> public static bool HightDragSensitivity{get{return false;}}}調(diào)用如果需要返回當(dāng)前狀態(tài)值,訂閱Event事件即可
LazyListBoxHelper.EventLazyListBoxHelperDelegateHandler += (args) =>{WebClient client = new WebClient();if (!client.IsBusy && LazyListBoxHelper._isBusy){LazyListBoxHelper._isBusy = false;LazyListBoxHelper._pageIndex += 20;this.progressBar.IsIndeterminate = true;this.progressBar.Visibility = Visibility.Visible;client.DownloadStringCompleted += (s, e) =>{if (e.Error == null){List<FindLinkInfo> list = GetFoodDetail(e.Result);for (int i = 0; i < list.Count; i++){this.ListFindData.Items.Add(list[i]);}LazyListBoxHelper._isBusy = true;}this.progressBar.IsIndeterminate = false;this.progressBar.Visibility = Visibility.Collapsed;};client.DownloadStringAsync(new Uri(String.Format(@"http://www.douguo.com/store/lists/c1t/{0}{1}", (this.listFindTitle.SelectedItem as FindLinkInfo).Url, LazyListBoxHelper._pageIndex), UriKind.Absolute));}};LazyListBoxHelper.InitLazyBox(ListFindData);}private void IninHot(){//檢查網(wǎng)路if (NetworkInterface.GetIsNetworkAvailable()){?
?
與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的LazyListBoxHelper 动态分页的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: svchost.exe介绍
- 下一篇: 数据中心容灾