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
Related
I've got a little problem. On a button press I need to open a panel with settings in animation. The thing is when I reduce width and height of a parent object (panel) it does not hide the child objects whatsoever. How can I make the parent object to influence the children's height and width when I change them in the parent?
If these objects are UI elements you can use add a Mask to the panel to hide any child objects that go outside of the area of the panel. As you can see below the square which is a child of the panel object does not render anything outside of the area of the panel.
If you want the UI elements to scale with the changing size of the panel then you should use anchors which will mean that the children of the panel will "anchor" themselves to the positions you set. Here's a short gif to illustrate how it works.
That's with the child image set to preserve it's aspect ratio, if you disable that setting then the box will stretch to perfectly fit the anchors.
If you want to scale your child objects with your parent canvas, you should set your render mode -> world space in your parent object.
I want to create an image made from several lines, ovals and rectangles. I think the best way of doing this will be to add them all as part of a shapeContainer and then I will need to add multiple instances of these images on my form.
I have created the image with no issues and added all shapes to a single shapeContainer. I now want the ability to be able to position this image anywhere in the form. I thought the logical way of doing this would be to just position the shapeContainer and because all shapes are positioned relative to their parent (the shapeContainer) the entire image should move with it.
However when I call the position function on the shapeContainer, nothing moves. I call this function from the form class (the form is the parent of the shapeContainer). The shapeContainer has its location set in the form.designer.cs file to point (0,0). I changed that but nothing happened.
How am I meant to set the position of a shapeContainer, and hence all shapes within it?
Thanks.
I'm building an application for users to create game terrain using hex tiles. I have a tree view with the various tile types and have successfully managed to load the images that I want to use (png's) into the tree as the node images.
I have used the code from here http://www.codeproject.com/Articles/14948/Hexagonal-grid-for-games-and-other-projects-Part as a basis for my project, although I have expanded it to allow for corner, and both "types" of half hexes.
What I want to accomplish is to drag a tile type from the Tile Catalogue tree view onto the hex grid drawn, and for that image to snap to the grid and align itself correctly. I imagine that the actual image to be drawn on the grid will end up being loaded separately as the treeview images are obviously very small versions of the original images.
Now I know there's a whole heap of items in there that I don't know how to do as yet but the first in the list is the drag and drop. All the searching I've done has turned up drag and drop examples for dragging within the treeview, or from one control to another and I'm not sure that those examples are relevant.
Can someone point me in the right direction to begin playing with this myself or give an example I could base what I need to do on?
I have a circular area cursor which is a circular winform (translucent) hooked to a cursor. On click, I want to get hold of the controls in the region of the parent winform just below the area of the cursor/form. These controls have to be arranged in circular layout on a different form. I am working on C#.NET.
Please tell how to access the controls of a winform and change their positions in context with my application described above? Like what classes, procedures, resources I need?
All controls on the form have Coordinates (X,Y) depicting there position on the form. So you would Need to get a list of Points (Point are Coordinates) Covered by your "Circle Cursor" then check each of those points for Controls. (Then De-dup your list)
See: C# Get the control at a certain position on a form
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).