How to scroll content in ScrollViewer WPF element

4 posts, 1 answers
  1. Stanislav
    Stanislav avatar
    1 posts
    Member since:
    May 2012

    Posted 09 Apr 2013 Link to this post

    Hello Telerik,

    There is ScrollViewer WPF element in the application. I was able to identify it, but I couldn't find any methods how I can scroll the content inside the element. How can I do so?

    Thank you.

    Kind Regards,
    Stanislav Hordiyenko
  2. Answer
    Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 12 Apr 2013 Link to this post

    Hi Stanislav,

    I apologize for the delay in getting back to you on this. Please take a look at this Silverlight code sample article. You can easily adapt it to suit your needs. Here's an example against one of our WPF demos:
    public GridViewCell FindGridViewCellByText(string cellToFind, RadGridView grid)
    {            
        ScrollViewer scrViewer = grid.Find.ByType("GridViewScrollViewer").CastAs<ScrollViewer>();
        double scrollPos = 0;
     
        do
        {                               
            for (int i = 0; i < grid.Rows.Count; i++)
            {
                if (grid.Rows[i].Cells[0].TextBlockContent.Contains(cellToFind))
                {                                               
                    return grid.Rows[i].Cells[0];
                }
            }
            
            scrollPos += scrViewer.ViewportHeight;
            scrViewer.InvokeMethod("ScrollToVerticalOffset", scrollPos);
            grid.Refresh(); // Refresh our cached copy of the grid.
     
        }
        while (scrollPos <= scrViewer.ExtentHeight);
        return null;
    }

    Then you can call that method like this:
    RadGridView grid = ActiveApplication.MainWindow.Find.ByName<RadGridView>("RadGridView1");
    Assert.IsNotNull(grid);
     
    FindGridViewCellByText("Cell 415 0", grid).User.Click();

    See this video demonstrating the execution.

    Hope this helps!

    Regards,
    Plamen
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  3. Stanislav
    Stanislav avatar
    1 posts
    Member since:
    May 2012

    Posted 15 Apr 2013 Link to this post

    Hello Plamen,

    Thank you for your reply. It is working. I have marked your message as an answer.

    Kind Regards,
    Stanislav Hordiyenko
  4. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 16 Apr 2013 Link to this post

    Hello Stanislav,

    Glad to hear it! Please contact us again if you have further problems.

    Regards,
    Plamen
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top