tags:

views:

488

answers:

2

Hi,

I have an ItemsControl in a ScrollViewer. The items in the ItemsControl are expanded to a DataTemplate which basically consists of an Adorner.

Now the problem is, when scrolling, the Visual Children of the Adorner are visible outside the ScrollViewer. Lets say I scroll from the Horizontal Offset 0 to 100, the Visual Children of the Adorner move to the left and are visible next to the ScrollViewer, although they should be hidden. Setting ClipToBounds on the ItemsControl or the ScrollViewer does not work.

I understand, that Adorner are rendered above all elements z-order wise, but they really shouldn't be visible in such cases as with the ScrollViewer. The adorned Element by the way behaves like expected and is not visible through the ScrollViewer.

Is there any easy way to "clip" the Adorners, so that they are only visible in the visible scroll area?

Thanks, Andrej

+1  A: 

In the following thread Wei Zhou re-templates the ScrollViewer so the button's Adorner is constrained.

Implement selection highlighting - advice please

Regards David

David Hollinshead
A: 

I've encountered the same problem when subclassing the WPFToolkit DataGrid to draw an adorner around the current cell.

The content of the ScrollViewer is rendered by a ScrollContentPresenter instance. ScrollContentPresenter has its own adorner layer, which is accessible through the ScrollContentPresenter.AdornerLayer property.

I found that my adorner correctly clips if I add it to that layer.

hwiechers
How do you get the ScrollContentPresenter from code?
skypecakes
I use VisualTreeHelper to search the visual tree until I find a descendant of type ScrollContentPresenter. Take a look at the method in this thread - http://wpf.codeplex.com/Thread/View.aspx?ThreadId=34542 .
hwiechers