System.Windows.Automation.ScrollPattern.Scroll C# (CSharp) 메소드

Scroll() 공개 메소드

public Scroll ( ScrollAmount horizontalAmount, ScrollAmount verticalAmount ) : void
horizontalAmount ScrollAmount
verticalAmount ScrollAmount
리턴 void
        public void Scroll(ScrollAmount horizontalAmount, ScrollAmount verticalAmount)
        {
            try
            {
                this._pattern.Scroll((UIAutomationClient.ScrollAmount)horizontalAmount, (UIAutomationClient.ScrollAmount)verticalAmount);
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
            }
        }

Usage Example

예제 #1
0
        private void ScrollIntoView(IElement container, ScrollPattern scrollbar, bool horizontally, bool incrementally)
        {
            // TODO To make scrolling more efficient, make big steps in the beginning.
            var step = incrementally ? ScrollAmount.SmallIncrement : ScrollAmount.SmallDecrement;

            bool done = false;
            do
            {
                // dimensions of partially displayed elements only reveal visible parts. (XAML-based only)
                int before = horizontally ? this.Width : this.Height;
                if (horizontally)
                {
                    scrollbar.Scroll(step, ScrollAmount.NoAmount);
                }
                else
                {
                    scrollbar.Scroll(ScrollAmount.NoAmount, step);
                }

                System.Threading.Thread.Sleep(20); // or the following readings could be stale
                this.ResetCache();
                int after = horizontally ? this.Width : this.Height;

                if (horizontally)
                {
                    if (incrementally)
                    {
                        done = this.X + this.Width <= container.X + container.Width;
                    }
                    else
                    {
                        done = this.X >= container.X;
                    }
                }
                else
                {
                    if (incrementally)
                    {
                        done = this.Y + this.Height <= container.Y + container.Height;
                    }
                    else
                    {
                        done = this.Y >= container.Y;
                    }
                }

                done = done && (after <= before); // leaving the element

                logger.Debug(
                    "Done? {0}; element [{1},{2}][{3},{4}] in the scrollable container [{5},{6}][{7},{8}]",
                    done, this.X, this.Y, this.Width, this.Height, container.X, container.Y, container.Width, container.Height);
            }
            while (!done);
        }