1. 程式人生 > >WPF判斷控制元件的滾動條是否移動到了最底部

WPF判斷控制元件的滾動條是否移動到了最底部

 	/// <summary>
        /// Get a bool value indicate whether is the VerticalScrollBar at buttom
        /// </summary>
        /// <returns>A bool value indicate whether is the VerticalScrollBar at buttom</returns>
        public bool IsVerticalScrollBarAtButtom
        {
            get
            {
                bool isAtButtom = false;

                // get the vertical scroll position
                double dVer = this.VerticalOffset;

                //get the vertical size of the scrollable content area
                double dViewport = this.ViewportHeight;

                //get the vertical size of the visible content area
                double dExtent = this.ExtentHeight;

                if (dVer != 0)
                {
                    if (dVer + dViewport == dExtent)
                    {
                        isAtButtom = true;
                    }
                    else
                    {
                        isAtButtom = false;
                    }
                }
                else
                {
                    isAtButtom = false;
                }

                if (this.VerticalScrollBarVisibility == ScrollBarVisibility.Disabled
                    || this.VerticalScrollBarVisibility == ScrollBarVisibility.Hidden)
                {
                    isAtButtom = true;
                }

                return isAtButtom;
            }
        } 
轉自:http://blog.csdn.net/abrahamcheng/article/details/7061813