zoukankan      html  css  js  c++  java
  • 转载:NonLive Scrolling延时滚动数据

    原文地址:http://blogs.msdn.com/vinsibal/archive/2008/05/22/wpf-3-5-sp1-feature-non-live-scrolling.aspx

    What is it?

    Before 3.5 SP1, the WPF ScrollViewer only supported live scrolling, which means the view of content the ScrollViewer contains updates immediately as the user moves the ScrollBar.  For controls like ItemsControl that had large data sets, live scrolling performance often looked sluggish.  Now in SP1, app developers have the option to use non-live scrolling.  The prime example that many people use to describe this is Outlook.  Scroll up and down your list of emails.  You’ll notice that the view updates when you have finished scrolling, which is non-live scrolling.  I did notice that when you don’t have a large set of emails it does use live scrolling.

    How do I use it?

    These are the new APIs added to ScrollViewer:

    public class ScrollViewer : ContentControl

    {

       public static readonly DependencyProperty IsDeferredScrollingEnabledProperty;

       public static bool GetIsDeferredScrollingEnabled(DependencyObject element) { }

       public static void SetIsDeferredScrollingEnabled(DependencyObject element,

                                                            bool value) { }

       public double ContentHorizontalOffset { get; }

       public double ContentVerticalOffset { get; }

    }

     

    This is opt-in functionality so IsDeferredScrollingEnabled is off by default.  ContentHorizontalOffset and ContentVerticalOffset are similar to HorizontalOffset and VerticalOffset except they only update their values to the new offset when the non-live scroll is completed.  Also note that when turned on, it will do non-live scrolling in both the horizontal and vertical directions.

    Well, that sounds easy enough.  I put together a really quick sample that uses non-live scrolling and in addition adds a cell counter to let you know where you are as you scroll.  This is similar to Word’s “Page: x of y” functionality.

    I use a ListView and bind IsDeferredScrollingEnabled to a CheckBox so you can turn it on and off dynamically.  The item counter is only visible when non-live scrolling is turned on.                    

    <ListView Name="mylv"

     ItemsSource="{Binding Mode=OneWay, Source={StaticResource products}}"

     ScrollViewer.IsDeferredScrollingEnabled="{Binding ElementName=myCheckBox, Path=IsChecked}">

     

    Note that IsDeferredScrollingEnabled is an attached property and works with ListView because a ScrollViewer is defined in the ListView's control template.  The counter I'm using is bound to a property of the ScrollViewer (VerticalOffset) which I use a converter to show the correct current and total items.   

    说明:当有大量数据的时候,滚动滚动条时即时的滚动视窗的数据会带来很差的性能,延迟
    滚动数据是指直到停止滚动时,才将数据滚动到当前位置。

    本例中用到的是ListView,它
    Represents a control that displays a list of data items,它的数据通过ListView.View定义,ListView的基类是ListBox,它的每一个Item是ListViewItem,
    ListViewItem的基类是ListBoxItem。

    本例中通过GetVisualChild找到了该ListView的ControlTemplate中的ScrollViewer的,并将ScrollViewer的VerticalOffset与例中的TextBlock的值绑定,通过一个Converter让该TextBlock
    显示当前滚动到的Item的Index。因为ScrollViewer实际上是在ListBox的ControlTemplate中定义的,所以只有当ContentRendered以后才能通过GetVisualChild找到它,所以例子中是在protected override void OnContentRendered(EventArgs e)中做这些绑定的。

    下载

  • 相关阅读:
    注意:MagickReadImageBlob() 引发的问题
    Notepad++ 【自动完成】与【输入时提示函数参数】互相冲突,无奈
    收藏:png8和png24的根本区别
    【物理分辨率】与【逻辑分辨率】
    算法
    算法
    Linux 用户和文件
    Oracle索引技术研究
    Linux Socket
    Linux Socket
  • 原文地址:https://www.cnblogs.com/bear831204/p/1344909.html
Copyright © 2011-2022 走看看