Click here to Skip to main content
16,018,650 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
i need a small help so I hope will find answer here.
I'm making school exam - a board game in C# using WPF. There are ellipses representing playing pieces. Meantime for dragging I used class "DragCanvas" from Josh Smith described here http://www.codeproject.com/KB/WPF/DraggingElementsInCanvas.aspx.
What is my problem is HOW TO DROP ELLIPSE TO THE EXACT POSITION ON THE GAME BOARD. I used grid to center the fields and now I plan to impement drop method which center dragged ellipse to the grid field, where mouseleftbutton was released. Simultaneously I want to allow pieces drop only inside specified grid positions and not elsewhere.
I'll really appreciate any idea what way to go because time is the worst enemy for me at the moment.
Thanks to all in advance.
Lukas.
Posted

If you want to set the position of an item within a grid to a particular coordinate (e.g., 200, 422) rather than a logical position (e.g., center), you can set the margin of the control. To allow the drop to only occur within certain regions, you can have your code check that the drop is within those regions during the drag (and you can change the drag icon accordingly to indicate whether or not a drop is allowed), or you can overlay grids on top of your primary grid and have the drag/drop functionality enabled on them rather than the primary grid (when a drop is performed, the control would then be added to the primary control rather than the overlay grids).
 
Share this answer
 
Thanks, that sounds logically. But there are questions related to it. Actually the "DragCanvas" library is applied to the whole window using "xmlns:local="clr-namespace:MyNamespace"" so all the objects of the window are draggable. I can deny dragging of some objects using "local:DragCanvas.CanBeDragged="False"" but If I use property "AllowDrop="False"" for any object it doesn't work (ellipse can be still dropped to it) and I don't know why.
I'm newbie in that so I would appreciate any saple code which helps me move.
 
Share this answer
 
Comments
AspDotNetDev 17-Aug-10 12:32pm    
Seems like that library was intended to be a quick solution for the simple types of drag/drop. Maybe you should manually perform drag/drop operations since you want to customize how it works.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900