4

我在Canvas有一个 Shape ,如下所示:

<ScrollViewer>

    <Border Height="342" Width="470" HorizontalAlignment="Left" 
        VerticalAlignment="Top" BorderThickness="3" BorderBrush="Black">

        <Canvas Background="White">
            <Rectangle Width="200" Height="200" Canvas.Left="103" 
                Canvas.Top="186" Fill="Red" />
        </Canvas>

    </Border>

</ScrollViewer>

即使 Rectangle 是 Canvas 子项,它也会在 Canvas 限制之外绘制,覆盖 Border 底部边框。如何使矩形仅在画布范围内绘制,确保超出的矩形部分不显示?

谢谢。

4

1 回答 1

14

这就是ClipToBounds属性的用途:

<Canvas Background="White" ClipToBounds="True"> 
    <Rectangle Width="200" Height="200" Canvas.Left="103" Canvas.Top="186" Fill="Red" /> 
</Canvas> 
于 2012-04-10T08:16:09.797 回答