How to draw Shape exclusively inside Canvas

.net, canvas, drawing, shapes, wpf

Solution

This is what the ClipToBounds property was made for:

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

Problem

I have a Shape inside Canvas, like this: ``` <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> ``` Even if the Rectangle is a Canvas children it's draw outside Canvas limits, covering Border bottom border. How can I make the Rectangle is draw only inside Canvas limits, ensuring that the part of rectangle that lies beyond is not displayed? Thanks.

Original source