How can i create a canvas of this kind - http://www.silverdiagram.net/Projects/SilverDiagram/SilverDiagram_Demo.aspx? I want to position the controls exactly aligned to each other. I want to help users to align it properly using auto-alignment (like visual studio) and by providing user the scale.
The Canvas is the right container to use as you can position its child control by coordinates. Your problem is more about moving elements around, which is in fact drag & drop.
You'll have to handle mouse events: MouseDown to select an item, MouseMove to detect a drag and MouseUp to drop it. During the move or at the drop, you can change the element's coordinates to auto-align it on a grid or compared to surrounding elements.
I successfully made such a project in Silverlight and used Adorners to add resize handlers to the elements.
I solved the panning and zooming question by putting the Canvas into a Viewbox, which was in a ScrollViewer. If you want to let the user control the zoom factor, apply a LayoutTransform to the Canvas (available in the Toolkit).
Related
In my WPF application I have a control that acts like a zoom box. You can zoom and drag its content. In my case this content is a grid that contains an image and some UserControls. These UserControls have to be positioned ontop of the image to highlight some segments of that image.
Here is an example (this is not an actual use case):
My question is, how should I position those red rectangles (what is the better practise here)?
By replacing the grid with a canvas and use Canvas.SetLeft resp. Canvas.SetTop?
or
By manipulating the RenderTransform of those rectangles?
Note: The rectangles are interactive (they have to interact with the mouse and maybe some other input devices).
I want to enable just two finger scrolling. I am developing uwp application on windows 10.How can I prevent to one finger scrolling for listview control in uwp?
Bests
You could probably do that, but I won't help you since that would be an evil feature that would confuse the users of your app. Instead, you should consider alternative solutions to whatever you'd like to happen when users use a single finger in a ScrollViewer.
Note that you're essentially trying to change how the ScrollViewer in the ListView template behaves. In most cases, you do that when you want to drag an item out of a list. Most people either handle the press and hold (aka long holding - the Holding event) or a cross-drag (dragging perpendicular to the ScrollViewer panning direction) and call ScrollViewer.CancelDirectManipulations() to stop panning and handle drag & drop instead.
If you just want a single finger panning to stop working - then you should not do that.
Scenario:
I have several canvases on my page. Lets say that half of the canvases contains a draggable grid with a background. All the canvases and the draggable items are created in code-behind.
When I drag an object (grid) from one canvas to another it works fine. But the issue is that the dragged object does not always stay on top of all other objects.
Question:
How can I make the dragged object (Grid) stay on top of all others objects on the page?
I tried to use Canvas.SetZindex(obj, 1000), but that did not work.
Any suggestion would be appreciated.
You can use additional "Operational" canvas which should be a top in the elements hierarchy.
Each time when you start drag and drop, you should translate dragging object's position from the owner's coordinate to the additional canvas coordinate and move element to the additional canvas. The reverse workflow should be implemented on end drag.
So as result dragging object always will be on top while dragging
I am using Sketchflow c# silverlight Expression Blend 4. I have a dragable control on a rectangle and I am trying to change the rectangle position in c# on mouse click. How can this be achieved? Thanks
If you want to be able to drag the rectangle around, make the parent of the control a canvas and then drag a MouseDragElementBehavior onto the control.
If you know what position you want it to move to and want it to work with just a click, you drag a ChangePropertyAction behavior onto it to set the margin property (or some other layout property).
I'm using WPF shapes to create Hexagons (for a game map) on a Canvas. After some playing around with ScrollViewer, I've decided to implement the scrolling and zoom of the map myself rather than using WPF functionality, just using WPF to get the events for mouse wheel, arrow keys etc. I'm placing the (Hex Map) Canvas as the last child inside a Dock Panel so it will get all the available remaining space. The Dock Panel will be set to be the content of the Main Window. But I want to find out how big the Canvas can be before I put any Children on the Canvas so that I can centre the screen over the Hex I want and only add the Shapes (Hexs) that can actually be seen. When zoomed out, a long way I will remove Polygons altogether and use another method of rendering and when zoomed in a long way I will add more details.
Is there any neat way of getting the available space? The only way that I can think of that will hopefully work is to get the current dimensions of the windows and subtract the dimensions of the outer elements of the Dock Panel, but that feels rather messy.
You may use the ActualWidth and ActualHeight properties of Canvas to determine size available to it. Be sure that HorizontalAlignment and VerticalAlignment are set to Stretch.