如何计算应用控件的缩放变换的大小

发布于 2024-12-03 16:07:00 字数 33 浏览 6 评论 0原文

如何计算WPF中缩放变换应用控件的增加的宽度和高度?

How to calculate increased width and height of the scale transform applied control in WPF?

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

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

发布评论

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

评论(2

风月客 2024-12-10 16:07:00
public static Rect GetAbsolutePlacement(this FrameworkElement visual)
{
    Point topLeft = visual.PointToScreen(new Point(0, 0));
    var bottomRight = visual.PointToScreen(new Point(visual.ActualWidth, visual.ActualHeight));

    var bounds = Rect.Empty;
    bounds.Union(topLeft);
    bounds.Union(bottomRight);

    return bounds;
}
public static Rect GetAbsolutePlacement(this FrameworkElement visual)
{
    Point topLeft = visual.PointToScreen(new Point(0, 0));
    var bottomRight = visual.PointToScreen(new Point(visual.ActualWidth, visual.ActualHeight));

    var bounds = Rect.Empty;
    bounds.Union(topLeft);
    bounds.Union(bottomRight);

    return bounds;
}
冷弦 2024-12-10 16:07:00

您可以使用 ActualHeight ActualWidth 属性。它们返回控件的真实值,而不是您请求的值。尽管这是呈现控件之后的值。

如果您想知道高度和宽度,那么您可以将转换应用于请求大小,但这些可能与实际值不匹配。

MSDN 有更多信息。

Height 和 Width 属性与 ActualHeight 和 ActualWidth 属性之间存在差异。例如,ActualHeight 属性是基于其他高度输入和布局系统的计算值。该值是由布局系统本身根据实际渲染通道设置的,因此可能会稍微落后于作为输入更改基础的属性(例如高度)的设置值。

由于 ActualHeight 是一个计算值,因此您应该注意,由于布局系统的各种操作,可能会对其进行多次或增量报告的更改。布局系统可能正在计算子元素所需的度量空间、父元素的约束等等。

You can use the ActualHeight and ActualWidth properties. These return the true values of the controls, not the values you have requested. Though this is the value after the control has been rendered.

If you want to know what the height and width will be then you could apply your transformation to the request sizes, but these might not match what the actual values will be.

The MSDN has more information.

There is a difference between the properties of Height and Width and ActualHeight and ActualWidth. For example, the ActualHeight property is a calculated value based on other height inputs and the layout system. The value is set by the layout system itself, based on an actual rendering pass, and may therefore lag slightly behind the set value of properties, such as Height, that are the basis of the input change.

Because ActualHeight is a calculated value, you should be aware that there could be multiple or incremental reported changes to it as a result of various operations by the layout system. The layout system may be calculating required measure space for child elements, constraints by the parent element, and so on.

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