0

If i have an element transformed outside the bounds of the WPF scrollviewer I can't seem to render it on top.

Consider the following example:

<Window x:Class="ScrollViewerContentTransform.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
    <Grid>

         <Grid.RowDefinitions>
             <RowDefinition/>
             <RowDefinition/>
         </Grid.RowDefinitions>

         <Border Grid.Row="0" Background="Blue" Panel.ZIndex="1"/>

         <ScrollViewer Grid.Row="1" Panel.ZIndex="2">
             <Grid>
                 <Border Width="30" Height="30" Background="Red">
                     <Border.RenderTransform>
                         <TranslateTransform Y="-80"/>
                     </Border.RenderTransform>
                 </Border>
             </Grid>
         </ScrollViewer>

    </Grid>
</Window>

Even when i set the zorder the red Border will still be hidden under the blue border.

http://imm.io/Sm2Q

If i replace the ScrollViewer with a Grid this will display as required. Any tips on how i can get the element to show on top when using the ScrollViewer?

  • The `Border` you have is on a different row, so it will never visually overlap with the `ScrollViewer` unless somewhere in your templates you've set `ClipToBounds` to false for Grid rows. – Ameen Jan 10 '13 at 14:04
  • If i switch the `Scrollviewer` with a `Grid` i get the visual result i was looking for. I would be guessing there was a solution for the `ScrollViewer` too. – Erlend Såstad Solberg Jan 10 '13 at 14:16

1 Answers1

1

As far as I know, it is impossible to remove content clipping when using ScrollViewer, because the ScrollViewer control template will generate a ScrollContentPresenter which in turn has the following implementation of the GetLayoutClip method:

protected override Geometry GetLayoutClip(Size layoutSlotSize) {
    return new RectangleGeometry(new Rect(base.RenderSize));
}

This class is Sealed so you can't derive from it to override this method. Thus consider removing ScrollViewer from your layout.

DmitryG
  • 17,677
  • 1
  • 30
  • 53