Ideas on how to zoom on a Chart control in WPF - c#

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.

Related

Unable to pan a canvas - Silverlight

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/

Is it possible to create a glow effect in C# 2.0?

I would like to create an outer glow effect on a UserControl derived class in c# 2.0 (WinForms). Is this (easily) possible?
If yes, please show me how :)
What I mean with "glow effect" is something like this:
Hope this helps http://www.codeproject.com/KB/buttons/VistaButton.aspx
I also rem reading an article where the author draws 2 rectangles over the button (each is covering half from top and bottom) and then when mouse is hover, he does some overlapping logic. I forgot the full logic. Sorry, ill think/search and come back with the answer.
Here are a few tutorials on how to easily achieve halo- and special effects on graphical objects in winforms:
Text Halo Effect
Text Effects
Drawing text with a drop shadow effect

Making selection of visual elements in Canvas easier

I have a Canvas based custom control that enables selection, dragging and resizing of visual children. I have so far Lines, Rectangles (without background) and images. Problem is, for selection, lines for example are hard to select obviously as they are 1 pixel high. Could you suggest a way to make them easily selectable? I'd like something along the lines of Visual Studio's selection, in which there are some pixels of "miss tolerance" when selecting something thin like a grid, you don't need to hit the exact pixel the line is at, few pixels around it are just as good, but I'm not sure how to implement that in WPF. Please help?
Thank you.
Perhaps what you are looking for can be easily achievable by using Adorner

Adding anchor line to a Bing Maps custom pushpin and allowing the user to drag

I am currently working on a Silverlight application using the Bing Map control, i am using a custom pushpin made up of an Image and a text block within a grid element, which works fine, this also allows me to have hover and right click events for each pushpin so all good so far, however there is a need for me to enable the user to drag the pushpin in any direction and have an a line connecting it to its actual position, sort of like an anchoring point.
I am struggling to see how to do this, I have seen lots of information on making the pushpins have the capability to be moved by the mouse but the line and anchor part is causing me a bit of a problem. Currently i keep my pushpins in various Observable Collections so that when they are updated the UI updates. If anyone has an Idea on a clean way of adding this functionality please let me know it will be much appreciated.
Many Thanks
I haven't got time to knock up a complete example. However I'll give away the basis of the solution. Replace the template with one based on a Canvas. For example you could have an ellipse to be the actual point on the map, a draggable border that has the ContentPresenter and a line to act as a tether.
The code needed is a) allow the Border to be dragged about and b) to move one end of the line about so that it lies under the Border.
I am still interested in other approaches but I have come up with a solution of paring my pushpin element with a MapPolyline, this in conjunction with the mouse handling to allow the user to drag the pushpin updates both, it is pretty effective and will do for now. I would still like to hear from anyone else with better suggestions though.

WPF snapping controls

my current free-time project, in order to dive into WPF MVVM, is a "digital" copy of an old puzzle I used to play a lot in my childhood. It basically is a simple puzzle where one has to fill a given space with different kind of pieces so the whole space is filled. But with the extra twist of being in hexagonal space.
Just to illustrate, this is what it currently looks like in WPF:
http://img190.imageshack.us/img190/2553/atomgridmolecule.png
So basically there is a number of predefined pieces(like the orange one above) which can be "plugged" into the given grid(the gray stuff above).
So the result might look something like this:
http://img30.imageshack.us/img30/2553/atomgridmolecule.png
I want the user(probably only me^^) to be able to drag and drop the pieces into the grid. I want the dragging to look natural meaning having the correct offset while dragging depending on where the user clicked the piece.
Both grid and molecule are the same control, a custom hexagonal panel control derived from the WPF Panel class.
The problem is on how to do the "plugging in" and especially the "unplugging".
I have two ideas on how I might tackle this:
Just color the cells in the grid and hiding the original piece
Pro:
Zero cost perfect alignment of the cells
Cons:
Recreating the piece at the right spot with the correct mouse offset if dragging out, seems impossibly? hard to do
Snapping the piece to the grid and show it on top
Pro:
Dragging out is a simple dragging operation, just as dragging in
Disadvantage:
Somehow have to align the piece with the underlying grid, some kind of snapping
So which approach should I take? Even more important how can I even implement this in WPF? Especially using a clean MVVM way.
Thanks so much for your help! Any input is highly appreciated!
EDIT:
Thanks Aran, I thought so too.
But how do I actually implement this now?
How can I actually get the coordinates?
All the orange circles are linked, so how can I "move" or better "plug" them in as one piece?
Im inclined to go with the second idea. a simple snapping would just be to test if the centre point of the circle you are dragging is within some tolerance factor of a circle on the grid and if so snap them.

Categories