How can I disable the drag event in LibraryBar control - c#

There are some LibraryBarItems in a LibraryBar control, when I drag horizontally, all the LibraryBarItems move.
But I need to disable this drag event, this means that when I drag the LibraryBar horizontally, nothing happens.
p.s. Actually I want to implement the drop event in horizontal direction rather than in Vertical direction.

I'd suggest adding a transparent visual item over the top of the control to capture input and only allow it through if want it to get through.

Related

Move controls between multiple containers in a single form

The questions says it all.
How can I move a control, say a PictureBox between multiple panels, or betwween a panel and a flow layout panel.
I'm aware I can drag and drop controls between multiple panels and such, however this is does not make the control visually movable between the containers. The mouse only changes to a diferent cursor and after you drag to the other control and release the mouse button the control appears on the other container. I require the control to be visually movable.
Can someone provide a simple example, so I can extract the idea to apply to my situation.
NOTE: Runtime of course.
Assuming you need it runtime:
You can save the control as bitmap using Control.SaveToBitmap method
Create cursor from image.
Set the current cursor which we created from control.
Once drag and drop completed reset the cursor.
Let's take a simple example of dragging a button around.
Suppose you have two types of container controls:
1) an X-Y layout
2) a flow layout (assume left to right)
When you click to drag the button, record the x-offset and y-offset from the click to the top left corner of the control. As well, record the index of the control within the Controls collection.
As the mouse moves, first check if the mouse has changed container controls.
If so, then remove the button from its current parent and add it to the new parent.
If the button is added to a flow control, then you need to calculate the new index. To do this, calculate the distance from the mouse to the closest edge of a bounding box of all other controls. Then if the mouse is left of the center of that control, insert to that control's index minus 1, otherwise insert to the right of that control (index + 1).
If the button is added to an X-Y layout, then the index doesn't matter that much. You can simple just set the button's location relative to the mouse plus the x-offset, and y-offset.
As the mouse is dragging, you will need to force the controls to refresh. I think calling Invalidate() on the container control should be sufficient.
This should give you the basic idea that you could use to start coding something.

ScatterViewItem Drag and Drop into RichTextBox

I have a ScatterView which consist of 2 items: an Image and a RichTextBox. RichTextBox has AllowDrop set to true.
When I drag the Image to the RichTextBox, the image disappears completely but RichTextBox's DragEnter and Drop event did not fire at all. Neither did PreviewDragEnter nor PreviewDrop.
I tried setting RichTextBox's AllowDrop to false, and the Image landed on top of the RichTextBox as expected.
How do I get the DragEnter and Drop event of RichTextBox to fire? The only thing that fires is the ScatterView's Drop event.
Drag & drop with Surface controls (like ScatterView) is different from normal Windows drag & drop. The thing being dragged is a 2d shape (not a single point) which could have multiple inputs dragging it around. Because of this, we couldn't shim the Surface drag drop functionality into the existing WPF drag drop APIs. Instead, you'll need to use attached events from the SurfaceDragDrop object like http://msdn.microsoft.com/en-us/library/microsoft.surface.presentation.surfacedragdrop.dragenter.aspx which are very similar to the WPF equivalents but enable Surface-friendly user experiences.

How to make movable control in silverlight

I'm trying to show some movable controls in silverlight. I've a grid, and dynamically I've to add some controls(I'm now trying with Thumb). And user can move those controls within the grid(in the space specified for the grid). I'm not saying about the Drag and Drop controls. Actually the controls are to move as a user press mouse left button on it and starts to drag it.
Please help. Thanks in advance.
What you describe is drag & drop only. You need to implement this.
handle the left mouse click, mouse move & left mouse up events for each of the controls you want to allow to be moved.
in the left mouse click event handler:
set a flag "drag_on" to True
in the mouse move event handler
check if "drag_on" is true, if false, return.
if drag_on is true, then set the control position (x, y) same as the mouse position.
you will get the mouse position from the parameter of the event handler
in the mouse up event, set drag_on to false. Also set the control position to that of mouse position.
Note:
you will need to transform the mouse position to the grid.
Get Absolute Position of element within the window in wpf
instead of setting the control position to the mouse position, you can also try setting the mouse position as the center of the control (homework for you).

Drag-Drop a Control between multiple canvas

Greetings,
I need to be able to drag and drop items that's contained in a Border.
So far I managed to find the border on the MouseLeftButtonDown event.
Now I wish for the item to move with the mouse when I have my mousebutton down.
I assume this can be done by simple settinga bool "dragging" to true when the item is clicked and then handle the moving in the MouseMove event.
But I can't seem to figure out how to move the item. Border doesn't have a property as Position or Location. Is there any way I can achieve what I want?
Perhaps there are controls for it that I dont know of?
Bit more background information:
I'm showing multiple columns (each column is a new canvas) with rows in it. Each row and canvas represent a cell. In a some cells I have a border containing a textblock with information. Upon clicking this border I wish for it to be bound to my mouse and move where I move my mouse.
I would recommend you use the Silverlight Toolkit which contains a framework for doing this sort of drag and drop work. Once installed open the documentation and lookup the PanelDragDropTarget control.

In WPF, how can I capture mouse on a Canvas and still find what controls the cursor is hovering over?

I have a custom Canvas control (inherited from Canvas) overlaid over a large area of User Controls. The idea is to draw paths between user controls (i.e. connector lines).
To capture mouse movement, I call Mouse.Capture(theCanvas) on MouseDown. This works beautifully, but the user controls under the canvas obviously no longer receive mouse events. Mouse.DirectlyOver always shows the canvas, so I can't really fake it by peeking at the current position and seeing which user control it's over.
So, I still need the Canvas for drawing paths, but how can I solve this one of the following ways:
Peek under the Canvas and see what the topmost control is right under it?
Get this MouseDown -> Track MouseMoves -> MouseUp workflow to work on the canvas without mouse captures?
Any other ideas welcome...
I'd agree that those are your two options. If you want to only forward some clicks to your usercontrols, then go with option 1, and hit test the controls under the canvas.
If you need your usercontrols to behave as though there is nothing covering them (textboxes, buttons etc), then i'd recommend using the PreviewMouseMove event on the user control's parent, as this can pick up and optionally "handle" events before the controls get at the event, but it won't block the event if you don't set handled to true

Categories

Resources