问题
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.
回答1:
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>
来源:https://stackoverflow.com/questions/10085229/how-to-draw-shape-exclusively-inside-canvas