John Sourcer
John Sourcer

Reputation: 451

RenderTransform without affecting children possibly Inverse

I'm resizing a canvas with touch events as follows:

e.Handled = true;
var transformation = MyCanvas.RenderTransform as MatrixTransform;
var matrix = transformation == null ? Matrix.Identity :transformation.Matrix;

matrix.ScaleAt(e.DeltaManipulation.Scale.X,
               e.DeltaManipulation.Scale.Y,
               e.ManipulationOrigin.X,
               e.ManipulationOrigin.Y);

MyCanvas.RenderTransform = new MatrixTransform(matrix);

The canvas has several child canvasses. I don't want to resize them and in fact need them to go smaller. So looked at RenderTransform.Inverse but am not having any joy.

Upvotes: 0

Views: 834

Answers (2)

Danny Varod
Danny Varod

Reputation: 18118

You can create a custom canvas by inheriting from Panel with

  1. A new dependency property: NonInheritableScale

  2. A binding between bind the transform's scale to the NonInhertiableScale property

  3. overrides of the MeasureOverride() and ArrangeOverride() methods,
    so that the take 1.0/NonInhertiableScale.X and 1.0/NonInhertiableScale.Y into account during the layout.

Here is an article on creating custom WPF panels that might help you (a search result, haven't read it).

Upvotes: 1

Emond
Emond

Reputation: 50712

EDIT after reading the comment below

In that case of a chart you might want to redraw the chart with different axis ranges. A RenderTransform might be not accurate enough and indeed you will have to scale back everything else (axis, labels, gridlines,...)

previous answer, still valid

You will have to iterate through the child canvases and scale them individually. As far as I know there is no build in support for what you want.

You will have to apply both the inverse scale transformation to negate the parent's resize and a scale transformation that will make them smaller.

Post the code you are using to get more detailed help and or feedback.

Upvotes: 1

Related Questions