Unable to pan a canvas - Silverlight - c#

I have seen lot of posts which demonstrate how to move objects in a Canvas but what I need is, a way to move either
1. the entire canvas along with its every child
or
2. move every object manually (which is certainly not advisable)
I have put my Canvas in a ScrollViewer.
My actual issue is : I m trying to zoom the canvas using ScaleTransform but after zooming, i also need to move the scroll viewer to a point such that the clicked point is at the center after zooming.
I tried Canvas.SetLeft() and Canvas.SetTop() but bad luck..
Any idea?
Thanks in Advance..

You can communicate with the ScrollViewer to make it scroll its content to a particular offset by using ScrollToVerticalOffset and ScrollToHorizontalOffset.
You'll need to calculate the correct offset by taking into account the size of the "viewport" i.e. the area that you can see of the content, and the zoom level.
http://go4answers.webhost4life.com/Example/center-zoom-wpf-problem-159135.aspx

This might be useful for what you are doing:
http://autoscroller.codeplex.com/

Related

Creating a Drag and Drop game

I'm creating a game that first requires the user to drag a certain textblock into a rectangle. Depending on which textblock is dropped into the rectangle, I want to store the contents of that specific textblock. It's important to note: I want the values stored only when the textblock is dropped inside the rectangle.
The problem: How can I make it so the computer knows that the rectangle contains the textblock?
Here's a screenshot to make things a little more clear: http://gyazo.com/3aa3a8678f11260889261fcd46366616.png
As of now, I can drag and drop the textblock fine, but the computer has no way of knowing if the textblock and rectangle intersect.
I've been trying to solve this problem for a few days now, and have spent a lot of time trying to use the system.drawing.rectangle.IntersectsWith()...only to find out that you can't dynamically add a system.drawing.rectangle to the canvas.
I've also thought of doing it by coordinates: if(textblock's coordinates are within the bounds of the rectangles coordinates)... However, I've spent time trying to figure out how to dynamically get the coordinate position of a xaml control, only to find out that you can't.
Could someone please offer some guidance? I've been working hard towards this and I've hit a dead end, so any degree of help will be great.
Thanks!

Ajax ModalPopupExtender positioning issue, not aligned in center

I am using Ajax toolkit and ModalPopExtender specifically, works fine, just have a big time issue with its positioning, I am using it to display images and all images have different height and width and hence some times it appears like bottom left of the screen with half of it going off the screen, I could have fixed it by specifying values for X and Y coordinates, but since the images sizes changes, if image is to small then user need to scroll the pointer all the way up.
The thing is it appears at a random location but as soon as I scroll or re size page, it relocates it self to the exact center of the screen (where its actually required).
Experts, kindly suggest a work around.
Thanks in advance.
Looks like there is no rigid solution to it, We contacted MSDN team as well, solved by replacing it with the Jquery Light Box.

Ideas on how to zoom on a Chart control in WPF

summarizing I have implemented a chart control as a simple Canvas with a Polyline on it. The next thing I need is to be able to zoom the chart.
I would like to know how would you that (just the idea, no details needed). What I would like to do is to create somehow a bigger Canvas and paint the line bigger and just show a part of the Canvas to the user, and the he drags the Chart it will move the Canvas. Something like in the following picture. Do you think this is possible?
Kael Rowan from Microsoft Research built a ZoomableCanvas class that may do exactly what you want. You can also see all the posts he wrote about it. You can even try a running XBAP example if your browser supports it.
We use the RenderTransform for this, create your zoom and pan matrix( or transform ) and apply that to your canvas. The nice thing is, that you can still have elements that can display behind or on top of the canvas with the identity transform or with another. For example for a grid or screen space elements like a minimap, which should always be visible. You might also want to look into this old question, which is somehow related.

Motion animation which is scalable?

is it true: a motion animation always based on a Canvas element – the Element which move is addressed via attached Property? Unfortunately it’s not possible to resize a Canvas-Element at Runtime!? So the Motion gets wrong when the user maximize the Window.
How can I create a motion animation which is scalable in WPF / C#?
Thanks a lot.
Draw your elements on the Bitmap,
and than draw your Bitmap with scale as you want
If you try resize not the self drawed elements, you can use "Viewbox" - content decorator that can stretch and scale a single child to fill the available space.
Here you can see how it works:
http://www.wpftutorials.com/2011/04/wpf-viewbox.html

Rotating Viewbox contents smoothly

I'm looking to teach myself better methods of doing things in WPF that I would normally do manually.
In this case, I have a ViewBox with an image in it. I also have a button that uses a DoubleAnimation to rotate the image 90 to the right.
This animation works fine, but obviously because it's square as it turns, the image does a "best fit" to the ViewBox which makes the rotation look quite bad, as it gets larger and smaller as its longest edge shrinks or grows to fit to that particular rotation angle.
I am looking for any advice on the best way to handle this using appropriate WPF methods. Obviously I could do all the calculations manually, but I would be more interested in finding a way to use the controls and methods built into the .NET architecture.
Thanks for your help.
If you only have an Image in your ViewBox, drop the view box. An image is already capable of stretching correctly with the Stretch attribute set to Uniform.
In any case, use a RenderTransform instead of a LayoutTransform, to avoid recalculating the position of the controls when the images rotates. RenderTransform will rotate the object after all position calculations are done so you'll be fine. Just add a margin around the image if you find that it pass over some control while rotating.

Categories