Search code examples
wpfuielementscaletransformlayouttransform

Find the applied ScaleTransform on a Control or UIElement?


I have a control sitting somewhere in my Window. At the root of this Window is a grid named MainGrid. I have a ScaleTransform applied on MainGrid's LayoutTransform that I use to zoom in on all the contents of my Window when the window's size grows. However, one of my controls usesBitmapCache on their canvases to optimize drawing performance. BitmapCache does not take into consideration any ScaleTransforms that might be applied to the control, so if I'm zoomed in, the control appears blurry.

BitmapCache does have a RenderAtScale property I can use to increase the scale of the cached image. However, the problem I have is that I don't know of an elegant way to find out what that Scale value needs to be. For now, I have a property on my control so that my Window can pass its scale value to the control. However, I would like it if I didn't need to rely on some external source passing in a scale value.

Is there any way a Control can get a summary of all the ScaleTransforms applied to it?


Solution

  • You can always recursively go through all of the Control's parents and sum their ScaleTransform.

    I don't think you can do it any other way.