If I want to clear the RenderTransform on a UIElement, what is the preferred way to do it? Both seem to work:
MyGrid.RenderTransform = null;
or
MyGrid.RenderTransform = Transform.Identity;
Does anyone know the difference or if there will be any side effects by setting it to null?
From MSDN:
https://msdn.microsoft.com/en-us/library/system.windows.media.transform.identity(v=vs.110).aspx
When you apply an identity matrix, it does not change the object. It is like multiplying by 1.
Also, the default value for UIElement.RenderTransform is Transform.Identity.
https://msdn.microsoft.com/en-us/library/system.windows.uielement.rendertransform(v=vs.110).aspx
There is no difference. In UIElement.ArrangeCore
source code you can see:
protected virtual void ArrangeCore(Rect finalRect)
{
this.RenderSize = finalRect.Size;
Transform transform = this.RenderTransform;
if (transform == Transform.Identity)
transform = (Transform) null;
// the rest ...
}
So if RenderTransform
is identity - it's treated as if it was null.
除此之外,如果将RenderTransform
属性设置为null
或Transform.Identity
,也没有太大的区别,您可能只想通过以下方式将属性重置为其默认值:
MyGrid.ClearValue(UIElement.RenderTransformProperty);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.