如何完全画形内帆布(How to draw Shape exclusively inside Can

2019-06-23 12:01发布

我有一个内部的形状画布 ,就像这样:

<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>

即使矩形是Canvas孩子是画外帆布限制,覆盖边框底部边框。 我怎样才能让矩形只画里面帆布限制,以确保一种超出矩形的部分不显示?

谢谢。

Answer 1:

这就是ClipToBounds财产被用于制造:

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


文章来源: How to draw Shape exclusively inside Canvas