最近整理电脑东西,虽然WP7已成过去式,记录下吧,代码是该别人的,增加委托传值,如得到获取数据的百分比等
正则抓取下厨房数据
下厨房正则 (? .+?)</span> <>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(? [^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*> 图片 (? .+?)</div> 介绍 (? .+?)</em> 配料 .+?
分页
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; //用于判断是否已经捕捉ScrollViewer static private bool _isHookedScrollEvents = false; static public event LazyListBoxHelperDelegateHandler EventLazyListBoxHelperDelegateHandler; public static void InitLazyBox(Control LazyBox) { ListscrollBarList = GetVisualChildCollection (LazyBox); foreach (ScrollBar scrollBar in scrollBarList) { if (scrollBar.Orientation == System.Windows.Controls.Orientation.Horizontal) { } else { scrollBar.ValueChanged += verticalScrollBar_ValueChanged; } } } #region 分页调用方法 /// /// 分页 /// /// /// 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 ListGetVisualChildCollection (object parent) where T : UIElement { List visualCollection = new List (); GetVisualChildCollection(parent as DependencyObject, visualCollection); return visualCollection; } public static void GetVisualChildCollection (DependencyObject parent, List 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 /// ///获取控件的子控件 /// ///子控件类 /// 父控件 ///public static T FindChildOfType (DependencyObject root) where T : class { var queue = new Queue (); 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; } /// /// 高敏感翻页 /// public static bool HightDragSensitivity { get { return false; } } }
调用如果需要返回当前状态值,订阅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) { Listlist = 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() { //检查网路 if (NetworkInterface.GetIsNetworkAvailable()) {