Reputation: 9825
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
Upvotes: 1
Views: 143
Reputation: 51
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.
Upvotes: 1