How to display texts and shapes with same width height at any zoom in Silverlight deep zoom applications? - silverlight

In my Silverlight application I display texts (textblock on canvas) as well as rectangles and lines (again shapes drawn on the canvas) over deep zoom images. I handle zoom in / out, pan and tilts. What is not realy cool in my opinion, is the way my vector objects look at different zoom factors. Of cause they become bigger or smaller.
Would you have any suggestions how to keep some of the objects dimentions look the same at any zoom? let's say, a line with StrokeThickness will always be of 10 screen pixels. or text block width, height 100 screen pix by 300 screen pix.
Thanks,
Val

It depends on how/where your objects are defined that you want to remain at 1:1 scale.
The 2 options I can think of are:
Render those objects in a canvas above the deep zoom (this means you need to work out the positions again yourself).
Apply reciprocal scaling to those objects (which means you work out what scale the item is going to display at and apply a 1/x scaling factor to them. That way the deep zoom shrinks an object that is scaled up to compensate and the 2 cancel out).
Hope this helps.

Related

Drawing shapes on image at consistent size regardless of dimensions

I have a program where I draw a bunch of custom shapes and objects on a canvas that sits on top of an image.
The images sizes vary hugely and they are stretched proportionally to fit the view.
When I draw the shapes, I also create some editing elements (frames and handles etc) for them so they can be scaled/rotated and the like.
The problem is that due to the differing dimensions/DPI of the images, these editing elements can either be massive or tiny depending on the image.
I have tried different methods like scaling the editing elements based on a scale factor calculated from the image sizes, but I'm not terribly happy with the result.
Can anyone suggest a good way to draw these editor elements at a consistent size regardless of the size of the image below it? As in a 1px or unit line will appear exactly the same on a 100 x 100 or 10000 x 10000 image?
I dabbled with adorners hoping they might be the solution, but they scale exactly the same as my custom shapes.
Any suggestions would be awesome, thank you!

Zooming into a Canvas without modifying the size of specific child controls

So I realize that I am venturing outside of the intended use of a Canvas here and will likely have to come up with a more manual solution. However, not being overly experienced in WPF I was hoping that there may be some solution which would allow me to continue using a Canvas control and the features it gives you for free.
The issue revolves around a Canvas which is used to zoom in and out of an image and some number of child controls that belong to the Canvas. These child controls are to be placed at various positions on the image and, as such, the Canvas works nicely in that it handles all of the layout/positioning for me as I zoom in or out.
However, one drawback is that the Canvas scales these child controls up as I zoom into the image, causing them to become too large to be usable in practice. What I am looking for is a solution that allows me to zoom into an image that belongs to a canvas without also zooming up the size of the child controls, preferably handling the layout for me.
I have tried modifying the width and height of these child controls as the zoom factor increases or decreases, but there is a slight lag time and it all looks a bit 'jerky'.
If it comes down to it I will simply do all of the zooming/panning/layout myself, but I thought I would ask first just to make sure that I am not missing anything that would allow me to tell the Canvas to not scale the size of certain controls. Thanks in advance.
You can bind the children's RenderTransform to the inverse of the Canvas' transform, see my answer to this similar question on rotation.
This is more of a thought than an answer, but what if you set a transform on the element that you did not want scaled that was the opposite of the canvas itself. So for example, if the canvas had a scale transform of 2.0, set the element to have a scale transform of 0.5. You could probably accomplish this by binding the transform values together using a value converter.
You'll probably want to make sure the element has a render transform origin of 0.5,0.5 so that it scales from the center.

How to maintain aspect ratio of a rectangle as user resizes the browser

I'm using a rectangle with either with a fill from either a video or image brush. As the user resizes the browser the rectangle resizes, which is fine, except that it must keep it's 4:3 aspect ratio. How can I keep the aspect ratio constant?
Have you tried adjusting the fill property on the video/image brush itself? There are various options to it, and im sure one of them will maintain the aspect ratio.
Image and MediaElement both have stretch properties that allow them to maintain their aspect ratio. You may need to change your control to use these instead of the brushes.
You could put your rectangle inside a Viewbox. It maintains the aspect ratio of its single child control, whilst scaling it to fit.

Scaling two Windows Forms controls while keeping the same ratio

I have 2 controls in a resize-able panel (1 datagridview and 1 textbox) with some space betwen and I need them both to scale in all directions with the panel. Problem is, since they're vertically stacked they run into each other when the panel scales vertically. I think I need some way to scale vertically while keeping the same ratio of the total panel size (ie, if the panel is scaled 2x, each control is scaled 2x) instead of anchoring them to all sides. Using C# if that matters, but I'm hoping for a non-programmatic solution.
A TableLayoutPanel was designed to provide this kind of scaling support. You'll need three rows with the middle one Absolute and the top and bottom Percent. Dock fill the controls in the rows, the rest is automatic.

Prevent Silverlight from scaling line width

When using the ScaleTransform class, Silverlight also scale the thickness of the strokes on the shapes that I display. But what if I don't want this behaviour? Is it possible to disable the scaling of strokes, or will I have to iterate over every shape object and set the reciprocal thickness?
A ScaleTransform is a render transform. It doesn't change the underlying layout just changes the way it is drawn on the screen. It isn't possible to have the points scale but not have the line thickness scale.

Resources