在 WPF 中,如何获取 FrameworkElement 的真实大小?

发布于 2024-08-17 16:34:25 字数 215 浏览 5 评论 0原文

在 WPF 中,如何获取 FrameworkElement 的真实大小,包括投影等效果添加的额外大小?

我有一个带有阴影的按钮。我以编程方式将其输出到 PNG 文件。我使用 ActualWidth 和 ActualHeight 来获取按钮的大小,但这是没有阴影的按钮的大小。

结果是带有投影的按钮被压缩为不带投影的按钮的大小。

有人知道如何计算带有阴影的按钮的大小吗?

In WPF, how do I get the true size of a FrameworkElement, including the extra size that an effect such as a drop shadow adds?

I have a button with a drop shadow on it. I am programmatically outputting it to a PNG file. I use ActualWidth and ActualHeight to get the size of the button, however this is the size of the button without the drop shadow.

The result is that the button with the drop shadow is squished into the size of the button without the drop shadow.

Anyone know how to figure out what the size of the button with the drop shadow would be?

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

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

发布评论

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

评论(1

一袭水袖舞倾城 2024-08-24 16:34:25

我不认为这实际上是可能的 - 如果您担心它,请将按钮包裹在边框中并使用填充;这样,阴影就会落在边框上,您不必对任何代码进行特殊处理来处理阴影使用的额外空间。

I don't believe that this is actually possible - if you're worried about it, wrap the button in a border and use padding; this way, the drop shadow falls on the border and you don't have to special-case any code to deal with the extra space used by the shadow.

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