我想知道是否有办法强制滚动条滚动画布。 我在canvasview中放置了canvas,我覆盖了measureoverride方法。当我到达画布可见部分的末端时,滚动条显示。但是我希望画布滚动,因为现在,尽管滚动条显示,画布不跟随项目。我希望你理解我,抱歉我的英语不好:)
答案 0 :(得分:2)
让我试试,
1)您在滚动查看器中托管了一个画布 2)当画布大小增加时,滚动查看器出现。 [由于,您已将水平或垂直滚动条可见性设置为自动] 3)你想要的是,当你到达画布的末尾时[画布的大小会增加,因此会出现滚动查看器的滚动条。]你希望滚动查看器的滚动条自动滚动以显示额外的空间。
如果,上述问题是正确的。这就是答案。
您必须根据画布的ActualWidth或ActualHeight进行计算,并相应地将值设置为ScrollToHorizontalOffset
或ScrollToVerticalOffset
属性。
答案 1 :(得分:2)
下面的示例将在蓝色画布中显示一个红色圆圈,如果它不适合窗口,它将具有垂直和水平滚动条。
<Window x:Class="WpfApplication.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<Canvas Width="500" Height="500" Background="Yellow">
<Ellipse
Stroke="Red" StrokeThickness="10"
Width="{Binding Path=ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}}}"
Height="{Binding Path=ActualHeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}}}" />
</Canvas>
</ScrollViewer>
</Window>