Wpf 如何为ScrollContentPresenter提供背景色?

Wpf 如何为ScrollContentPresenter提供背景色?,wpf,scrollviewer,Wpf,Scrollviewer,我创建了一个很好的滚动/缩放/平移用户控件,但现在我意识到,ScrollContentPresenter没有可以设置的背景色 也就是说,当我将画布缩小到更小的区域时,在ScrollViewer和canvas之间,一个区域保持完全白色,这就是ScrollContentPresenter 有简单的解决办法吗 一些代码解释了这一点: <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Au

我创建了一个很好的滚动/缩放/平移用户控件,但现在我意识到,
ScrollContentPresenter
没有可以设置的背景色

也就是说,当我将画布缩小到更小的区域时,在
ScrollViewer
canvas
之间,一个区域保持完全白色,这就是
ScrollContentPresenter

有简单的解决办法吗

一些代码解释了这一点:

<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>

使用此代码,缩小时,
ScrollContentPresenter
将以白色显示。然后画布在其中居中


如果代码中没有
网格的
宽度
高度
b索引,则
滚动内容演示器
在缩小时不可见。然后画布固定在左上角。

您可能需要在
ScrollContentPresenter
的父对象(网格
画布
或包含
ScrollContentPresenter
的任何对象)上设置
背景

看起来似乎有道理,但不是我代码中的网格,但ScrollViewer的内部网格就是罪魁祸首。确定:
var Grid=Tools.FindChildVisualTree(ScrollViewer);grid.Background=画笔.Red