views:

35

answers:

2

Here's an example image of what I mean: example

The gray rectangle is the bounding box of a control that draws the blue lines and dots in it's OnRender(...) method. The red ovals mark places where it happens.

  • Why is that possible?
  • How can it be avoided?
A: 

http://msdn.microsoft.com/en-us/library/ms750441.aspx has detailed information about the architectural design of WPF to answer why it is possible.

To avoid it you want to use the clip property of your element.

 <Rectangle Fill="Yellow" Height="100" Width="200" StrokeThickness="2" Stroke="Black">
   <Rectangle.Clip>
     <EllipseGeometry Center="200,100" RadiusX="50" RadiusY="50" />
   </Rectangle.Clip>
 </Rectangle>

Check out http://msdn.microsoft.com/en-us/library/cc189065%28v=VS.95%29.aspx for more details.

PhilB
Thanks, I assumed it has to do with something like a display tree, but couldn't find any documentation about it. For the how it can be avoided, I was searching for something easier than doing manual clipping - and I just found the solution I was hoping for: http://msdn.microsoft.com/en-us/library/ms588678.aspx
Wiesel
+2  A: 

Here's the perfect answer to my second question, at least when using a rectangular shaped control:

<object ClipToBounds="True" />

More details on the MSDN.

Wiesel