为什么控件可以在其边界框之外绘制?

发布于 2024-09-19 11:47:52 字数 207 浏览 2 评论 0原文

下面是我的意思的示例图像: 示例

灰色矩形是控件的边界框,在其 OnRender(...) 方法中绘制蓝色线条和点。红色椭圆标记了发生的位置。

  • 为什么这可能?
  • 如何避免呢?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你的心境我的脸 2024-09-26 11:47:52

这是我的第二个问题的完美答案,至少在使用矩形控件时是这样:

<object ClipToBounds="True" />

有关 MSDN

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.

川水往事 2024-09-26 11:47:52

https://msdn.microsoft.com/en -us/library/ms750441(v=vs.100).aspx有关于WPF架构设计的详细信息来回答为什么它是可能的。

为了避免这种情况,您需要使用 clip 属性。

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

请查看 http://msdn.microsoft。 com/en-us/library/cc189065%28v=VS.95%29.aspx 了解更多详细信息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文