0

Currently I am stuck with a problem that is simple on the first sight. Its about automated GUI testing.

I want to make a row/cell of a WPF DatGrid completely visible by scrolling using ScrollIntoView(row) and then accessing the row/cell directly after. Unfortunately scrolling in ScrollViewer seems to happen asynchronously. This means I need to wait for the scrolling to finish before accessing the row/cell. For this purpose I found the ScrollChanged event I can subscribe.

There is only one detail I can not solve: If the row/cell I want to access is already visible (and no scrolling is necessary) I do not get that event and the algorithm gets stuck. I was not able to find a reliable way to predict if a call to ScrollIntoView(row) actually scrolls.

Any idea how to solve this?

Silicomancer
  • 8,604
  • 10
  • 63
  • 130
  • did you try `dataGrid.UpdateLayout();` after you `ScrollIntoView`? – dkozl Jun 20 '13 at 10:13
  • Thanks! This really seems to work! I could imagine that this trick could get handy in some other cases too. Is it documented somewhere? How did you know that updating the layout also updates the view port? – Silicomancer Jun 20 '13 at 12:45
  • Yes, it standard `UIElement` method. I've put the link into the answer. – dkozl Jun 20 '13 at 12:57

1 Answers1

1

To make sure layout is updated call UIElement.UpdateLayout after you ScrollIntoView and before you want to use item. Quoting MSDN it

Ensures that all visual child elements of this element are properly updated for layout.

dkozl
  • 32,814
  • 8
  • 87
  • 89