Page 1 of 1

Disable viewbox for specific children

Posted: 27 Apr 2023, 11:41
by Sumel007
Hi!

I wanted to ask if there's some way to disable viewbox scaling for one specific image. I have a complicated user control that is inside the Viewbox, and inside that control is one image that I do not want to scale. I do not want to move the image outside that user control, since I want it to be rendered in between other elements (and it would also be quite complicated in general).

One solution that I've found here https://www.codeproject.com/Articles/11 ... c-Elements creates an inverse scaling transform. It seems like that would work (however I worry if it would degrade the image quality ie. make it downscale and then upscale again, or if the backend implementation is smart enough to see that the viewbox and scale transform should cancel out). I cannot get it to work in Noesis though, since it uses the following line to get the viewbox's transform
var transform = 
            ((ContainerVisual)VisualTreeHelper.GetChild(sender as DependencyObject, 0)).Transform;
            if (transform != null && viewBox != null)
and the ContainerVisual is not accessible in the C# Noesis NuGet package. Is there something I could do to work around the lack of ContainerVisual issue? Or maybe some completely other way to disable the viewbox scaling for one specific image.

Re: Disable viewbox for specific children

Posted: 27 Apr 2023, 12:03
by sfernandez
Hi,

The transforms will cancel before any rendering is performed, so the image quality won't be affected.
In order to get the scale applied by the Viewbox you can do the following in Noesis:
ScaleTransform scale = ((UIElement)VisualTreeHelper.GetChild(viewbox, 0)).RenderTransform as ScaleTransform;
Then you can just apply the inverse scaling to your image.