I´d like to drag and drop objects in wpf solution via multitouch gesture. I get two userControls. I am able to drag an item from userControl1 and place it anywhere in my application. It sounds good so far, but here is the problem:
If I move userControl1, the dragged and placed item is going to move with userControl1. That means even though I moved an item before out of userControl1, it is still connected to that userControl.
I would like to drag an item from userControl1 and place it in userControl2. There shouldn´t be any data binding between the item and userControl1 anymore, when I drag the item out of the userControl.
Does anybody know a suitable answer for my problem?
Check out the SurfaceDragDrop class in the "Surface Toolkit for Windows Touch"
Related
In windows form application, i created a usercontrol page. Here, I need to add a myowncontrol from tool box.
I just added myowncontrol in the tool box. by the way of browsing dll and placed it in tool box.
Here, when i drag and drop any one of default control, which can easily dragged and placed in the usercontrol page. But when i try to drag and drop myowncontrol into usercontrol page , its not working.
Can't able to drag and drop.
(i mean i can pick the control from the tool box but i can't able to place it where i want)
what is the problem in my area?
I'll admit that this does not directly answer your question, but I am wondering if you have tried to programmatically add the control to a Form? You would need to add a reference to the DLL that contains the UserControl and then do something similar to below in your source code.
var myCtrl = new MyControl(); //your UserControl class here
myCtrl.Location = new Point(25,25); //give it a location
this.Controls.Add(myCtrl); //add it
Also another thought... Are you sure that it's not really being added and it's just not visible? For a Form or UserControl in the Visual Studio Properties Window there is a drop-down at the top which contains all the controls that have been added.
I'm trying to build a WPF control inheriting from Selector and I want to change the state of the control when one of its items are selected in the design surface. Despite hooking on a debugger, I can't seem to capture any useful events from the control. I've managed to capture it being initialised and the wrappers for its child elements being initialised around the items of the selection, but I can't see any change of state, or event being triggered when the control is selected.
Importantly, I want to detect when the item is selected either by the user selecting the control in the design view or in the markup.
I'm trying to achieve a behaviour like that of the TabControl, where selecting a tab brings it to the front and exposes any content associated with the tab. I can't fathom how it works at design-time though.
What do I need to do to detect that a control is selected?
Previously I tried to Drag and Drop an object out of a LibraryContainer onto a ScatterView and vice-versa and it was rather simple being that the LibraryContainer, LibraryStack and LibraryBar support drag and drop events by default. That combined with the DragDropScatterView.cs from the ShoppingCart example provided with the Surface 2.0 SDK was pretty straightforward.
Now I want to be able to drag and drop a UserControl onto a ScatterView4 and vice-versa, i.e., something like this: http://goo.gl/zZIdg.
From what I researched there is a way to do that and can be found here: http://msdn.microsoft.com/en-us/library/ff727736.aspx. However, here they don't use the DragDropScatterView.cs, it's done a different way. You have two ObservableCollections (a source and a target), the ScatterViewItems and the SurfaceListBox.
One thing I don't like in this example is that the ScatterViewItems that can be dragged don't really have a scale property because when the user clicks on the ScatterViewItem, it creates a visual style and hides the ScatterViewItem and when you drop it, it updates the coordinates and orientation of that ScatterViewItem and makes it visible. I decided not to go this way, since I want a normal ScatterViewItem behaviour.
The basic thing I want to do is to have, for example a Label, and on the side a ScatterView and be able to drag that Label (creating a visual cursor - already done) and drop it on the ScatterView, creating a ScatterViewItem that has the same properties as the original Label. I tried doing this with the DragDropScatterView.cs but when I'm using a Label my droppingCursor.Data (on the DragDropScatterView.cs) is null and I think that happens because the draggedElement.DataContext (on the LabelView.xaml.cs) is also null, however this is not null when I have a SurfaceListBox.
I provide a code sample here: http://sdrv.ms/VDuHq5. In the SurfaceWindow1.xaml there is the TagVisualization and the container of the ScatterView, the LabelView.xaml is called inside the `TagVisualization.
If someone can help me on this I would really appreciate it.
I managed to solve my problem and here is a brief explanation on how I did it:
I searched and found this. I then used this SurfaceListBox with these drag and drop events and combined it with the DragDropScatterView class, so each time a new ScatterViewItem was created I would have a normal ScatterView control of my custom object. With this method you also have to create a Visual Cursor, i.e., what you'll see when you'e dragging the item from the SurfaceListBox.
The thing that was puzzling me and that Serge Calderara (from the MSDN Surface Forum) helped me with, was that I kept trying to associate these drag and drop events to a Label for example, or a UserControl even, but I was looking at things the wrong way. In most cases the best solution for you is to have a container, and in that container you put the UserControls you want and you only associate the drag and drop events to that container, and not to each individual item. With that in mind it was rather easy to put things together, I created my UserControls and populated the SurfaceListBox (wich is my container) with an ItemTemplateSelector and I used that same Selector for the ScatterView (that's receiving the items from the container). In my object class I just defined a variable to save which type of UserControl I'll have and return the DataTemplate accordingly.
With this I created a SurfaceListBox with two custom UserControls that I can drag and drop to a ScatterView and back. A working sample with MVVM pattern can be found here: http://sdrv.ms/10SjKaH.
I hope it can help others and it helped me. If you have any questions or suggestions please feel free to ask/tell.
I have FlowLayoutPanel and UserControl's on it with drag & drop reordering. This sort of works. But the problem is that child controls prevent dragging of the actual parent UserControl.
So my question is how to enable dragging of a UserControl that contains child controls?
If I understand you right I had the same problem as you and I solved it by propagating events of the child element to it's parent.
If you have a draggable UserControl containing a label. You have to call the events of the UserControl when the events of the label occurs. E.g. in the Label's OnMouseDown() call the UserControl's OnMouseDown() and just pass the Event-Args. I didn't find a better way than handling each event that is required for drag and drop separately.
I have a windows form that contains two usercontrols. One usercontrol contains two list views. The other usercontrol has a grid.
Within the first usercontrol the two list views drag and drop their contents between each other.
The grid usercontrol is setup to dragdrop onto the listview usercontrol.
The problem is that the drag drop event within the listview usercontrol always takes precedence over the dragdrop between the two usercontrols.
So if I drag from the grid usercontrol over the listview usercontrol it will execute the internal dragdrop event of the listview control.
In other words it fires this event
lv_groupActivites_DragDrop
instead of
reservationScheduleBooking1_DragDrop
Is there anyway of specifying which drag drop event should be fired?
You are dragging from the grid in one user control and trying to drop onto a specific listview on the other user control or anywhere on the other user control?
If you want to drop anywhere on the other user control, I think you will need to setup the apprporate event handler on that user control to respond. If you want to drop on to a specific listview that also accepts drag events from the other listview you will need to do extra work in your event handler on that listview to figure out where the drag initiated from.