Question

I created a nice working scroll/zoom/pan usercontrol, but now I realize that the ScrollContentPresenter has no background color that I can set.

That is, when I zoom out my canvas is scaled into a smaller area and between the ScrollViewer and the Canvas an area remains completely white, it is the ScrollContentPresenter.

Is there an easy solution?

Some code to explain this:

<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
   <Grid Name="grid" RenderTransformOrigin="0.5,0.5"
         Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ScrollViewer}}, Path=ActualWidth}"
         Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ScrollViewer}}, Path=ActualHeight}">
   <Grid.LayoutTransform>
       <TransformGroup>
           <ScaleTransform x:Name="scaleTransform"/>
        </TransformGroup>
   </Grid.LayoutTransform>
       <ListBox ... />
   </Grid>
</ScrollViewer>

With this code the ScrollContentPresenter becomes visible in white when zooming out. The canvas is then centered in it.

Without the Width & Height binidng of Grid in the code the ScrollContentPresenter remains invisible when zooming out. The canvas is then fixed in the top-left.

Was it helpful?

Solution

You probably would need to set the Background on whatever the Parent of the ScrollContentPresenter is (the Grid or Canvas or whatever that contains the ScrollContentPresenter).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top