开发者

Why can a control draw outside its bounding box?

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?


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.


https://msdn.microsoft.com/en-us/library/ms750441(v=vs.100).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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜