1

I have a WPF UserControl which acts like a Viewport (I call it "viewport" in the following context). This viewport can zoom and pan its content (I think the zooming uses either the Layout- or RenderTransform to zoom the content). Basically the content is just a Canvas. This Canvas contains some shapes and some TextBoxes which are used to display meta data of the shapes. If the zoom factor is 1 all is fine but if I zoom out, the canvas shrinks and also the TextBoxes which causes the meta data to be unreadable because the text is so tiny.

How can I force the TextBoxes to counter-zoom so that they doesn't change there size on the screen?

I have thought about passing the Transform of the viewport (that causes the zoom) to the TextBoxes (somehow) and apply its inverse to them but this seems wrong to me. Another aproach is to use Adorner that holds the TextBoxes. I found a topic about Adorners with Controls here on Stackoverflow but im not sure if this aproach is better then the other.

So if someone got a better solution I would appreciate it.

Thanks in advance

Community
  • 1
  • 1
Timo
  • 9,269
  • 2
  • 28
  • 58

1 Answers1

1

There is a Transform.Inverse property, that you can use to "undo" your parent control's transform. So you basically bind your parent control to MyTransform, and all child controls to MyTransform.Inverse. That way the transform is applied to the children's position, but not their size.

I agree that it "feels wrong", but I'm pretty sure it is your best option.

wilford
  • 51
  • 2
  • 1
    The problem is that the contents of the viewport should be scaled. But the contents of the contents should not be scaled. I solved it by creating a class which is used as data context. This class holds a property that stores a double that represents the scale. The viewport has a property "ContentScale" and an according changed event. So basically im binding the ContentScale to my data context which is again bound to the control that should be unscaled. In the Control I'm converting the double to a ScaleTransform (1/ContentScale for x and y). – Timo Apr 28 '16 at 13:58
  • I think I understood you correctly - binding to your parent transform's Inverse-property should give you the exact same effect of what you are now doing manually. Everything inside your viewport would continue to scale as expected, except all those children to which you explicitly apply ViewPort.RenderTransform.Inverse. Anyway, glad you got it working. – wilford Apr 28 '16 at 14:20
  • Yes binding the Transform would make things easier but as I said I'm not quite sure if one of the transforms is actually used and the viewport is a black box. But thanks for your help. – Timo Apr 29 '16 at 06:07