Download Source Code
In this section we will show you the details on the Drag.
The main idea on the drag is to pick up the data that will be transferred as well as defining the data type that is transferred. The data type lets the system tell if the item can be dropped when the mouse moves over a particular area.
In the IDragable interface we have the following:
The DataType property returns the type of the data that is being dragged.
The Remove method removes the source data for a move operation. If it's a copy operation then you simply don't call it. In our application we will only implement the move operation per our business logic, though you can add the copy functionality if you like.
The IDragable interface is implemented in the ViewModel. In both the CandidateViewModel and the OrgElementViewModel we return the DataType as ElementViewModel:
The Remove method in the ViewModel simply calls the Model to perform the business logic on removing the element. You can look into the source code if you are interested in the details of the business logic.
Next we define the drag behavior, meaning what would we like to do when a drag occurs. The FrameworkElementDragBehavior class inherits from the System.Windows.Interactivity.Behavior class, which allows you to define the actions that you like to perform for events such as a mouse click or a mouse move. Below is the code:
The AssociatedObject property from the parent class is the UI control in which the behavior is bound to. For example, if we add this behavior to a StackPanel xaml declaration, then the AssociatedObject is the StackPanel.
If the mouse is clicked down (and kept down) and moves out of the area then we start the drag operation. When you have nested controls such as the detailed view of the organization chart this is the most reliable way to detect the drag. If you don't have nested controls you may just use the MouseMove event and check the mouse pressed state from MouseEventArgs.
In the MouseLeave event we check the DataContext of the UI control and see if it implements IDragable. If yes then that means the item can be dragged. We then get the data type being dragged by calling the IDragable interface and start the drag operation by calling System.Windows.DragDrop.DoDragDrop method.
To enable the drag operation we simply add the xaml to the View for the control that you would like to drag. For example in the TreeView we defined the following to drag the StackPanel from the TreeView:
And the same goes for the Detailed View:
and the CandidateView:
Next we will see the implementation of the Drop.
Future series of articles on sharepoint:
sharepoint list -- the concepts of sharepoint list and how to effectively manage it
sharepoint version control -- the internals of sharepoint version control and how to administer and manage the versions
sharepoint permissions -- how to manage the permissions in a large enterprise sharepoint environment
sharepoint server farm -- how to set up a high availability sharepoint server farm
sharepoint document library -- the details on how to get your ways around the document library in sharepoint
sharepoint configuration -- the configurations needed for different sharepoint network scenarios
sharepoint css -- making the most out of customizing sharepoint frontend
sharepoint web services -- some of the most convienent ways to communicate with the internals of sharepoint