我想将canvas
组件与scrollViewer
绑定。我有一个放大和缩小canvas
的功能,我希望使用符合scrollViewer
实际尺寸的canvas
添加滚动条。
我的画布的放大/缩小功能:
private void canvasShopMap_MouseWheel(object sender, MouseWheelEventArgs e)
{
if (e.Delta > 0)
{
scaleTransform.ScaleX += scaleRate;
scaleTransform.ScaleY += scaleRate;
}
else
{
scaleTransform.ScaleX -= scaleRate;
scaleTransform.ScaleY -= scaleRate;
}
canvasShopMap.RenderTransform = scaleTransform;
}
我尝试做的XAML代码(是的,我知道scrollViewer在这里是canvas,但我尝试了上面的函数用于scrollViewer并且它没有工作; /):
<Canvas x:Name="canvasShopMap" HorizontalAlignment="Left" Height="500" VerticalAlignment="Top" Width="690" MouseLeftButtonDown="canvasShopMap_MouseLeftButtonDown" MouseWheel="canvasShopMap_MouseWheel" Margin="272,139,0,0">
<ScrollViewer x:Name="scrollViewerForCanvas" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"
Height="{Binding Parent.ActualHeight , Mode=OneWay, RelativeSource={RelativeSource Self}}"
Width="{Binding Parent.ActualWidth , Mode=OneWay, RelativeSource={RelativeSource Self}}" MouseWheel="scrollViewerForCanvas_MouseWheel">
</ScrollViewer>
</Canvas>
有什么建议吗?