Reputation: 896
<Grid Height="333">
<Canvas Margin="0,-41">
<Rectangle Height="60" Width="72" Canvas.Left="73" Canvas.Top="355">
<Rectangle.Fill>
<ImageBrush Stretch="None" ImageSource="aaa.png"/>
</Rectangle.Fill>
</Rectangle>
</Canvas>
</Grid>
The problem is Rectangle is visible out of the Grid and I don't want this. What should I do?
Upvotes: 2
Views: 1178
Reputation: 70142
You need to clip the Grid. I wrote an attached property that will do this for you. See the following blog post:
http://www.scottlogic.co.uk/blog/colin/2009/05/silverlight-cliptobounds-can-i-clip-it-yes-you-can/
You can use it as follows:
<Grid Height="333" util:Clip.ToBounds="true">
<Canvas Margin="0,-41">
<Rectangle Height="60" Width="72" Canvas.Left="73" Canvas.Top="355">
<Rectangle.Fill>
<ImageBrush Stretch="None" ImageSource="aaa.png"/>
</Rectangle.Fill>
</Rectangle>
</Canvas>
</Grid>
Internally this attached behaviour sets the FrameworkElement.Clip
property to the required geometry based on the current size of the element it is attached to.
Upvotes: 3