Stop viewbox from messing with my font size ?
-
Saturday, August 25, 2007 7:59 AMModerator
I have a control which contains an image, and on which I draw lines and text using tools that work by creating paths, textboxes and text areas. I've wrapped all this in a viewbox, which has solved some issues I had getting tools to scale with an image. My problem now is that my text tool renders text in all sorts of different font sizes. I've tried to calculate a font size that compensates for the actions of the viewbox, using the image size and the window size, but I cannot get the text to always be the same size for all images. Is there a way to calculate the text size of a control that is inside a viewbox, so that it remains consistent, or another way to make the control always show the font in the same size ?
Thanks
Christian
All Replies
-
Saturday, August 25, 2007 6:24 PM
I just blogged a solution to your question, and included a demo project. Hopefully it does what you need. http://joshsmithonwpf.wordpress.com/2007/08/25/rendering-text-in-the-adorner-layer/
-
Saturday, August 25, 2007 10:04 PMModerator
Thanks Josh, that solves my main issue, but creates new ones.
My code drags out a textbox, then I enter the text, and finally, I create the textblock which copies the RenderTransform from the TextBox, to position it properly. This obvioulsy no longer works. I looked at the articles you linked to, and copied the code to set the position of the text from your CP article, and dropped the render transform from the textblock. Now it sort of works, but the textblock seems to be positioned relative to the whole screen. I've made some attempts to get the grid position as an offset, they don't seem to work. I believe what I need to do is create an AdornerDecorator, which will force the custom adorner to snap the adorner's properties to the grid. But, I can't seem to make that work.
I also need to be able to find my textarea later ( to undo/redo/clear tools ). I guess I need to iterate over the items in the viewboxes adornerlayer for that ?
Thanks for your help, I really appreciate it. this has been a real bear for me, and I'm under a lot of pressure to get it done 4 days ago ( literally, now )

