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