How to draw a shape exclusively inside the canvas

I have a form inside Canvas , for example:

<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 though the Rectangle is a child of the Canvas, it stretches the canvas's borders, covering the bottom border. How can I get the Rectangle to only draw inside the canvas's borders, ensuring that the portion of the rectangle that is outside is not shown?

Thank.

+3


source to share


1 answer


This ClipToBounds property was made for:



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

      

+12


source







All Articles