zoukankan      html  css  js  c++  java
  • LazyListBoxHelper 动态分页

    最近整理电脑东西,虽然WP7已成过去式,记录下吧,代码是该别人的,增加委托传值,如得到获取数据的百分比等

    正则抓取下厨房数据

    下厨房正则
    <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> 菜系详细
    <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;
            //用于判断是否已经捕捉ScrollViewer
            static 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  分页调用方法
    
            /// <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;
                }
            }
        }

    调用如果需要返回当前状态值,订阅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()
            {
                //检查网路
                if (NetworkInterface.GetIsNetworkAvailable())
                {

     

  • 相关阅读:
    【梦断代码】与我们队的相似之处
    梦断代码 之 你失败过吗
    梦断代码 之 程序人生
    C#中父类转换为子类
    C#中Dictionary泛型集合7种常见的用法
    Linux 常见命令 目录处理指令
    使用XSLT+XML生成网页
    我心目中的Asp.net核心对象
    配色速成
    VS.NET中JavaScript隐藏特性
  • 原文地址:https://www.cnblogs.com/Irving/p/2756077.html
Copyright © 2011-2022 走看看