Can ScaleTransform create everything on canvas / grid except 1 control?

Given the following canvas:

<Canvas>
    <Canvas.LayoutTransform>
        <ScaleTransform ScaleX="1" ScaleY="1" CenterX=".5" CenterY=".5" />
    </Canvas.LayoutTransform>
    <Button x:Name="scaleButton" Content="Scale Me" Canvas.Top="10" Canvas.Left="10" />
    <Button x:Name="dontScaleButton" Content="DON'T Scale Me" Canvas.Top="10" Canvas.Left="50" />
</Canvas>

Is it possible to scale 1 button, but not the other, when ScaleX and ScaleY change?

+3
source share
3 answers

Not in XAML. You can do this in code by building the inverse transform and applying it to an object that you don't want to transform.

If you want to show interest, you can create a dependency property that you can attach in XAML to any object that you don’t want to transform using any parent transformations. This dependency property will accept the parent transform, build the inverse transform, and apply it to the object to which it is bound.

+9
source

, , , :

<Button x:Name="dontScaleButton" Content="DON'T Scale Me" Canvas.Top="10" Canvas.Left="50"
        LayoutTransform="{Binding LayoutTransform.Inverse,
                                  RelativeSource={RelativeSource AncestorType=Canvas}}"/>

, , .

+6

You can also restructure items so that items that you don't want to scale with Canvasare not actually children of this Canvas.

<Canvas>
    <Canvas>
        <Canvas.LayoutTransform>
            <ScaleTransform ScaleX="1" ScaleY="1" CenterX=".5" CenterY=".5" />
        </Canvas.LayoutTransform>
        <Button x:Name="scaleButton" Content="Scale Me" Canvas.Top="10" Canvas.Left="10" />
    </Canvas>
    <Button x:Name="dontScaleButton" Content="DON'T Scale Me" Canvas.Top="10" Canvas.Left="50" />
</Canvas>
+3
source

Source: https://habr.com/ru/post/1697736/


All Articles