How to calculate the size of the scale transform applied control
How to calculate incr开发者_StackOverflow社区eased width and height of the scale transform applied control in WPF?
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;
}
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.
精彩评论