### ICloneableDragItem Interface Implementation Example Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/types.md Example implementation of the ICloneableDragItem interface. This allows items to be cloned when a drop operation with copy semantics is performed. ```csharp public class MyItem : ICloneableDragItem { public string Name { get; set; } public object CloneItem(IDropInfo dropInfo) { return new MyItem { Name = this.Name + " - Copy" }; } } ``` -------------------------------- ### Drop Example Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-handlers.md Implement the Drop method to perform the actual item insertion into the target collection. This example extracts data, determines the insert index, and inserts items. ```csharp public void Drop(IDropInfo dropInfo) { var items = DefaultDropHandler.ExtractData(dropInfo.Data); var insertIndex = dropInfo.InsertIndex; foreach (var item in items) { dropInfo.TargetCollection.TryGetList()?.Insert(insertIndex++, item); } } ``` -------------------------------- ### Custom Drag Handler Example Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-handlers.md Example of creating a custom drag handler by inheriting from DefaultDragHandler to add validation logic before a drag operation starts. ```APIDOC ## Custom Drag Handler for Validation ### Description This example shows how to create a custom drag handler that overrides the `CanStartDrag` method to implement custom validation logic. ### Code Example ```csharp public class ValidatingDragHandler : DefaultDragHandler { public override bool CanStartDrag(IDragInfo dragInfo) { if (dragInfo.SourceItem is ValidationModel model) { return model.IsValid; } return base.CanStartDrag(dragInfo); } } ``` ``` -------------------------------- ### DragOver Example Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-handlers.md Implement the DragOver method to specify drop effects, data, and visual feedback. This example allows moving 'Person' objects and provides insert adorner feedback. ```csharp public void DragOver(IDropInfo dropInfo) { if (dropInfo.DragInfo?.SourceItem is Person draggedPerson) { dropInfo.Effects = DragDropEffects.Move; dropInfo.Data = draggedPerson; dropInfo.DropTargetAdorner = DropTargetAdorners.Insert; } } ``` -------------------------------- ### Custom Drop Handler Example Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-handlers.md Example of implementing a custom drop handler with specific business logic for handling dropped items, including visual feedback and data manipulation. ```APIDOC ## Custom Drop Handler with Business Logic ### Description This example demonstrates a custom drop handler that defines custom behavior for `DragOver` (setting effects and adorner) and `Drop` (modifying items and inserting them into a target list). ### Code Example ```csharp public class CustomDropHandler : DefaultDropHandler { public override void DragOver(IDropInfo dropInfo) { var targetList = dropInfo.TargetCollection as IList; if (targetList != null && DefaultDropHandler.CanAcceptData(dropInfo)) { dropInfo.Effects = DragDropEffects.Move; dropInfo.DropTargetAdorner = DropTargetAdorners.Insert; } } public override void Drop(IDropInfo dropInfo) { var items = DefaultDropHandler.ExtractData(dropInfo.Data).Cast(); var targetList = dropInfo.TargetCollection as IList; foreach (var item in items) { item.LastModified = DateTime.Now; targetList?.Insert(dropInfo.InsertIndex++, item); } } } ``` ``` -------------------------------- ### IDragItemSource Interface Implementation Example Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/types.md Example implementation of the IDragItemSource interface. This interface notifies items when they have been dropped, allowing them to react to the drop event. ```csharp public class MyItem : IDragItemSource { public void ItemDropped(IDropInfo dropInfo) { Debug.WriteLine($"Item dropped at index {dropInfo.InsertIndex}"); } } ``` -------------------------------- ### StartDrag Method Example Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-handlers.md Example implementation of the StartDrag method for IDragSource. This method is called when a drag operation is about to begin. It sets the data to be dragged and the allowed effects (e.g., Move, Copy). ```csharp public void StartDrag(IDragInfo dragInfo) { if (dragInfo.SourceItems.Count > 0) { dragInfo.Data = dragInfo.SourceItem; dragInfo.Effects = DragDropEffects.Move; } } ``` -------------------------------- ### Get or Set DestinationText Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets or sets the text describing the drop destination, shown in the adorner. ```csharp string DestinationText { get; set; } ``` -------------------------------- ### CanStartDrag Method Example Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-handlers.md Example implementation of the CanStartDrag method for IDragSource. This method determines if a drag operation is permitted from the current source item. It returns true to allow the drag, and false to prevent it. ```csharp public bool CanStartDrag(IDragInfo dragInfo) { return dragInfo.SourceItem is not null; } ``` -------------------------------- ### Get or Set DropHintText Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets or sets the user-facing hint message displayed during a drop operation. ```csharp string DropHintText { get; set; } ``` -------------------------------- ### Get or Set EffectText Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets or sets the text describing the operation (e.g., "Move", "Copy"), displayed in the adorner. ```csharp string EffectText { get; set; } ``` -------------------------------- ### VisualSource Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the UIElement that initiated the drag operation. ```APIDOC ## VisualSource Property ### Description Gets the UIElement that initiated the drag. ### Property `UIElement VisualSource { get; }` ### Parameters N/A ### Return Value - **UIElement** - The control with `IsDragSource="True"` ``` -------------------------------- ### VisualTarget Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the UIElement that serves as the drop target. ```APIDOC ## VisualTarget Property ### Description Gets the UIElement that is the drop target. ### Method `UIElement VisualTarget { get; }` ### Parameters #### Property - **VisualTarget** (UIElement) - Readonly - The control with `IsDropTarget="True"`. ``` -------------------------------- ### DropTargetHighlightAdorner Usage Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/types.md Example of how to set the DropTargetAdorner to Highlight for a drop target. This visually indicates the entire drop target area. ```csharp dropInfo.DropTargetAdorner = DropTargetAdorners.Highlight; ``` -------------------------------- ### Enable Drop Target Hints Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/adorners-and-visual-feedback.md Enables the display of visual hints on drop target elements to guide the user during drag and drop operations. ```csharp DragDrop.SetUseDropTargetHint(target, true); ``` -------------------------------- ### Usage in XAML Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-handlers.md Example of how to apply custom drag and drop handlers to a control in XAML using attached properties. ```APIDOC ## Usage in XAML ### Description This example shows how to enable drag and drop functionality on a `ListBox` and assign custom drag and drop handlers using XAML attached properties. ### Code Example ```xml ``` ``` -------------------------------- ### Applying Drop Hint Template to ListBox Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/extension-interfaces.md Usage example of applying the defined DropHintTemplate to a ListBox using a local attached property. ```xml ``` -------------------------------- ### IDragInfo.SourceItems Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets all selected items being dragged. ```APIDOC ## SourceItems Property Gets all selected items being dragged. ```csharp IEnumerable SourceItems { get; } ``` | Type | Description | |-------------|-------------------------------------| | IEnumerable | All selected items in the source control | **Remarks:** - May include multiple items if multiple selection is enabled - Used by `DefaultDragHandler` to determine what to drag - Empty collection if no items selected ``` -------------------------------- ### TargetItem Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the item under the cursor in the target collection. ```APIDOC ## TargetItem Property ### Description Gets the item under the cursor in the target collection. ### Method `object TargetItem { get; }` ### Parameters #### Property - **TargetItem** (object) - Readonly - Item under cursor, or null. ### Remarks Useful for drop validation and determining insertion context. ``` -------------------------------- ### TargetCollection Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the bound collection on the target control. ```APIDOC ## TargetCollection Property ### Description Gets the bound collection on the target control. ### Method `IEnumerable TargetCollection { get; }` ### Parameters #### Property - **TargetCollection** (IEnumerable) - Readonly - Bound items source, or null if unbound. ### Remarks Used by handlers to determine where to insert items. Null if target is unbound. ``` -------------------------------- ### DropHintText Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets or sets the text displayed in the drop hint adorner. ```APIDOC ## DropHintText Property ### Description Gets or sets the text displayed in the drop hint. ### Property Signature ```csharp string DropHintText { get; set; } ``` ### Type string ### Remarks User-facing hint message. ``` -------------------------------- ### DragInfo Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the drag information from the source, if the drag originated within the framework. ```APIDOC ## DragInfo Property ### Description Gets the drag information from the source (if drag originated within the framework). ### Method `IDragInfo DragInfo { get; }` ### Parameters #### Property - **DragInfo** (IDragInfo) - Readonly - Source drag info, or null if external drag. ### Remarks Null when dragging from outside the application. ``` -------------------------------- ### VisualTargetItem Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the item container element currently under the cursor. ```APIDOC ## VisualTargetItem Property ### Description Gets the item container element under the cursor. ### Method `UIElement VisualTargetItem { get; }` ### Parameters #### Property - **VisualTargetItem** (UIElement) - Readonly - Container at cursor position, or null. ### Remarks For ItemsControl, this is the generated container (ListBoxItem, TreeViewItem, etc.). ``` -------------------------------- ### DestinationText Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets or sets the destination description text for the adorner. ```APIDOC ## DestinationText Property ### Description Gets or sets the destination description text for the adorner. ### Property Signature ```csharp string DestinationText { get; set; } ``` ### Type string ### Remarks Text describing the drop destination. ``` -------------------------------- ### KeyStates Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the current keyboard modifier state during the drop. ```APIDOC ## KeyStates Property ### Description Gets the current keyboard modifier state during the drop. ### Property Signature ```csharp DragDropKeyStates KeyStates { get; } ``` ### Type DragDropKeyStates ### Remarks Represents modifier keys and mouse buttons pressed during the drag operation, such as ControlKey, ShiftKey, AltKey, LeftMouseButton, RightMouseButton. ``` -------------------------------- ### DataFormat Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets or sets the clipboard data format for the drag operation. ```APIDOC ## DataFormat Property ### Description Gets or sets the clipboard data format for the drag operation. ### Property `DataFormat DataFormat { get; set; }` ### Parameters N/A ### Return Value - **DataFormat** - Clipboard format (Default: `DragDrop.DataFormat` ("GongSolutions.Wpf.DragDrop")) ### Remarks Custom formats can be used for interoperability with other applications. ``` -------------------------------- ### Set and Get DragDropHandler Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets or sets the function that performs the Windows drag-and-drop operation. Defaults to System.Windows.DragDrop.DoDragDrop. ```csharp Func DragDropHandler { get; set; } ``` -------------------------------- ### DragDrop Class - Static Entry Point Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/API-OVERVIEW.md The DragDrop class serves as the primary entry point for the framework, exposing attached properties and default handlers for configuring drag-and-drop behavior. ```csharp public static partial class DragDrop { // Attached properties for UI elements public static DependencyProperty IsDragSourceProperty { get; } public static DependencyProperty IsDropTargetProperty { get; } public static DependencyProperty DragHandlerProperty { get; } public static DependencyProperty DropHandlerProperty { get; } // ... 40+ more properties // Static methods to get/set properties public static bool GetIsDragSource(DependencyObject element) public static void SetIsDragSource(DependencyObject element, bool value) // ... corresponding Get/Set for each property // Default implementations public static IDragSource DefaultDragHandler { get; } public static IDropTarget DefaultDropHandler { get; } public static DataFormat DataFormat { get; } } ``` -------------------------------- ### DropTargetHintState Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets or sets the visual state of the drop hint (None, Active, or Error). ```APIDOC ## DropTargetHintState Property ### Description Gets or sets the visual state of the drop hint (None, Active, or Error). ### Method `DropHintState DropTargetHintState { get; set; }` ### Parameters #### Property - **DropTargetHintState** (DropHintState) - Required - Visual hint state (None, Active, Error). ``` -------------------------------- ### Get KeyStates Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the current keyboard modifier state during the drop operation. This includes ControlKey, ShiftKey, AltKey, LeftMouseButton, and RightMouseButton states. ```csharp DragDropKeyStates KeyStates { get; } ``` -------------------------------- ### DropTargetHintState Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets or sets the visual state of the drop hint (None, Active, or Error). ```csharp DropHintState DropTargetHintState { get; set; } ``` -------------------------------- ### Implement Custom IDropInfoBuilder Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/extension-interfaces.md Example implementation of IDropInfoBuilder to customize drop information creation for a specific control. Returns null to use the default builder for other controls. ```csharp public class ThirdPartyControlDropInfoBuilder : IDropInfoBuilder { public IDropInfo CreateDropInfo(object sender, DragEventArgs e, IDragInfo dragInfo, EventType eventType) { if (!(sender is MyCustomControl)) { return null; } var dropInfo = new DropInfo(sender, e, dragInfo, eventType); // Customize dropInfo for third-party control return dropInfo; } } ``` -------------------------------- ### Data Property (IDropInfo) Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets or sets the data to be dropped. Must be set in DragOver to enable drop. ```APIDOC ## Data Property (IDropInfo) ### Description Gets or sets the data to be dropped. **Must be set in DragOver to enable drop.** ### Property `object Data { get; set; }` ### Parameters N/A ### Return Value - **object** - The data from IDragInfo, or custom data ### Remarks - Initialize from `IDragInfo.Data` in drop handlers - Can be modified to transform dropped data - Must be set for drop to proceed (in addition to `Effects`) ``` -------------------------------- ### GongSolutions.WPF.DragDrop File Structure Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/INDEX.md This snippet outlines the directory structure of the GongSolutions.WPF.DragDrop framework, indicating the location of key documentation files. ```text /output/ ├── INDEX.md (this file) ├── API-OVERVIEW.md (start here) ├── types.md (all public types & enums) ├── configuration-and-scenarios.md (how-to and patterns) └── api-reference/ ├── dragdrop-attached-properties.md (40+ attached properties) ├── drag-drop-handlers.md (IDragSource & IDropTarget) ├── drag-drop-info.md (IDragInfo & IDropInfo) ├── extension-interfaces.md (advanced customization) └── adorners-and-visual-feedback.md (visual customization) ``` -------------------------------- ### Set and Get Data Object Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets or sets the IDataObject used for the drag operation. This is for advanced usage, allowing custom data formats on the clipboard. ```csharp object DataObject { get; set; } ``` -------------------------------- ### Drop Hints Configuration Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/configuration-and-scenarios.md Enables visual hints to indicate valid drop targets before a drag operation begins. Requires a DataTemplate to define the appearance of the hint. ```xml ``` ```xml ``` -------------------------------- ### Get InsertPosition Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the relative position where items will be inserted compared to the target item. Possible values include TopLeft, TopRight, BottomLeft, BottomRight, and TargetItemCenter. ```csharp RelativeInsertPosition InsertPosition { get; } ``` -------------------------------- ### Set and Get Data Format Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets or sets the clipboard data format for the drag operation. The default format is 'GongSolutions.Wpf.DragDrop'. Custom formats can be used for interoperability. ```csharp DataFormat DataFormat { get; set; } ``` -------------------------------- ### IDropHintInfo Interface Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/types.md Contains information for drop hint display, including drag info, adorner type, and hint text. ```APIDOC ## IDropHintInfo Interface ### Description Contains information for drop hint display. ### Properties - **DragInfo** (IDragInfo) - Gets information about the current drag operation. - **DropTargetHintAdorner** (Type) - Gets or sets the adorner type for the drop target hint. - **DropHintText** (string) - Gets or sets the text for the drop hint. - **DropTargetHintState** (DropHintState) - Gets or sets the state of the drop target hint. ``` -------------------------------- ### Get DragDrop Copy Key State Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the keyboard modifier key (ControlKey, ShiftKey, AltKey, or None) that triggers copy mode for the current drag operation. ```csharp DragDropKeyStates DragDropCopyKeyState { get; } ``` -------------------------------- ### Implement Custom IDragInfoBuilder Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/extension-interfaces.md Example implementation of IDragInfoBuilder to customize drag information creation for a specific control. Returns null to use the default builder for other controls. ```csharp public class ThirdPartyControlDragInfoBuilder : IDragInfoBuilder { public IDragInfo CreateDragInfo(object sender, object originalSource, MouseButton mouseButton, Func getPosition) { // Use default builder for standard controls if (!(sender is MyCustomControl)) { return null; } var customControl = sender as MyCustomControl; var dragInfo = new DragInfo(sender, originalSource, mouseButton, getPosition); // Customize dragInfo for third-party control return dragInfo; } } ``` -------------------------------- ### Get IsSameDragDropContextAsSource Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets whether the target is in the same drag-drop context as the source. This property prevents drops between controls with different DragDropContext property values. It returns true if contexts match or if both are empty. ```csharp bool IsSameDragDropContextAsSource { get; } ``` -------------------------------- ### Get or Set AcceptChildItem Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets or sets whether child items can be accepted during a drop operation, typically used for TreeView nesting. Set to true to allow dropping an item as a child of another. ```csharp bool AcceptChildItem { get; set; } ``` -------------------------------- ### Static Properties Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/dragdrop-attached-properties.md Provides access to default implementations for drag and drop handlers and data formats. These are used when custom handlers are not explicitly specified. ```APIDOC ## Static Properties The `DragDrop` class also provides static properties for accessing default implementations: ```csharp public static DataFormat DataFormat { get; } public static IDragSource DefaultDragHandler { get; } public static IDropTarget DefaultDropHandler { get; } public static IRootElementFinder DefaultRootElementFinder { get; } ``` These defaults are used when no custom handler is specified via attached properties. ``` -------------------------------- ### Get or Set NotHandled Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets or sets whether this drop should be handled by child elements instead. Set to true to pass the drop event to child handlers; otherwise, set to false to handle it at the current level. ```csharp bool NotHandled { get; set; } ``` -------------------------------- ### Drag Preview and Opacity Configuration Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/configuration-and-scenarios.md Enables the display of a default drag adorner (preview) for dragged items and allows customization of its opacity. Use this to provide visual feedback during drag operations. ```xml ``` -------------------------------- ### Custom Drop Handler with Business Logic Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-handlers.md Example of a custom drop handler that implements DragOver and Drop methods to handle data insertion with custom logic, including updating item properties. ```csharp public class CustomDropHandler : DefaultDropHandler { public override void DragOver(IDropInfo dropInfo) { var targetList = dropInfo.TargetCollection as IList; if (targetList != null && DefaultDropHandler.CanAcceptData(dropInfo)) { dropInfo.Effects = DragDropEffects.Move; dropInfo.DropTargetAdorner = DropTargetAdorners.Insert; } } public override void Drop(IDropInfo dropInfo) { var items = DefaultDropHandler.ExtractData(dropInfo.Data).Cast(); var targetList = dropInfo.TargetCollection as IList; foreach (var item in items) { item.LastModified = DateTime.Now; targetList?.Insert(dropInfo.InsertIndex++, item); } } } ``` -------------------------------- ### IDragInfo.SourceItem Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the single item being dragged. ```APIDOC ## SourceItem Property Gets the single item being dragged. ```csharp object SourceItem { get; } ``` | Type | Description | |--------|-------------------------------------------| | object | The item under the mouse when drag started, or null | **Remarks:** - Only set if drag was initiated from an item container - For single selections in most controls - See `SourceItems` for multiple selections ``` -------------------------------- ### Implement Custom Drop Behavior Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/README.md This C# code demonstrates how to implement custom drop behavior by creating a ViewModel that implements the IDropTarget interface. It includes logic for handling drag-over events and performing drop operations. ```csharp public class MyViewModel : IDropTarget { public void DragOver(IDropInfo dropInfo) { if (DefaultDropHandler.CanAcceptData(dropInfo)) { dropInfo.Effects = DragDropEffects.Move; dropInfo.DropTargetAdorner = DropTargetAdorners.Insert; } } public void Drop(IDropInfo dropInfo) { // Implement insertion logic } } ``` -------------------------------- ### Access Default Drag and Drop Handlers Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/dragdrop-attached-properties.md Provides access to the default implementations for drag source, drop target, and root element finding. These are used when custom handlers are not explicitly set. ```csharp public static DataFormat DataFormat { get; } public static IDragSource DefaultDragHandler { get; } public static IDropTarget DefaultDropHandler { get; } public static IRootElementFinder DefaultRootElementFinder { get; } ``` -------------------------------- ### Configure DropTargetHighlightAdorner Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/adorners-and-visual-feedback.md Configures the drop target to use a highlight adorner. This adorner fills the entire drop target area with a specified brush. ```csharp // Set the highlight adorner dropInfo.DropTargetAdorner = DropTargetAdorners.Highlight; // Configure the highlight color DragDrop.SetDropTargetHighlightBrush(target, Brushes.LightBlue); ``` ```xml ``` -------------------------------- ### UseDropTargetHintProperty Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/dragdrop-attached-properties.md Enables the drop hint feature that shows potential drop targets before drop occurs. When enabled, visual cues are provided to indicate valid drop locations. ```APIDOC ## UseDropTargetHintProperty ### Description Enables the drop hint feature that shows potential drop targets before drop occurs. ### Property - **UseDropTargetHint** (bool) - Required - Enable drop hint adorner display ### Default Value false ``` -------------------------------- ### Implement CloneableDragItem for Copying Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/API-OVERVIEW.md This C# code demonstrates how to implement a custom drop handler that supports copying items when the Ctrl key is pressed. It checks if the operation should be a copy and clones the item if it implements ICloneableDragItem. ```csharp public class MyDropHandler : DefaultDropHandler { public override void Drop(IDropInfo dropInfo) { var isCopy = DefaultDropHandler.ShouldCopyData(dropInfo); var items = DefaultDropHandler.ExtractData(dropInfo.Data); foreach (var item in items) { var insertItem = isCopy && item is ICloneableDragItem cloneable ? cloneable.CloneItem(dropInfo) : item; dropInfo.TargetCollection.TryGetList()?.Insert( dropInfo.InsertIndex++, insertItem); } } } ``` -------------------------------- ### VisualSourceFlowDirection Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the flow direction of the source element. ```APIDOC ## VisualSourceFlowDirection Property ### Description Gets the flow direction (left-to-right or right-to-left) of the source. ### Property `FlowDirection VisualSourceFlowDirection { get; }` ### Parameters N/A ### Return Value - **FlowDirection** - Text direction of source (LeftToRight, RightToLeft) ``` -------------------------------- ### Custom Drop Target Adorner Implementation Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/extension-interfaces.md Example of creating a custom adorner by extending DropTargetAdorner. This adorner draws a blue rectangle with a light blue fill. ```csharp public class CustomDropAdorner : DropTargetAdorner { public CustomDropAdorner(UIElement adornedElement) : base(adornedElement) { } protected override void OnRender(DrawingContext drawingContext) { // Draw custom visual feedback var rect = new Rect(AdornedElement.RenderSize); drawingContext.DrawRectangle(Brushes.LightBlue, new Pen(Brushes.Blue, 2), rect); } } ``` -------------------------------- ### VisualSourceItem Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the item container element being dragged. ```APIDOC ## VisualSourceItem Property ### Description Gets the item container element being dragged (e.g., ListBoxItem for ListBox). ### Property `UIElement VisualSourceItem { get; }` ### Parameters N/A ### Return Value - **UIElement** - Container of the dragged item, or null ### Remarks - For ItemsControl, this is the generated container (ListBoxItem, TreeViewItem, etc.) - Useful for extracting visual information about the dragged item ``` -------------------------------- ### XAML for Custom Drop Hint Template Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/adorners-and-visual-feedback.md Defines a custom DataTemplate for the drop hint, allowing for a unique visual representation of the drop zone. ```xml ``` -------------------------------- ### Inspect Drag and Drop Context Values Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/configuration-and-scenarios.md Log the drag-and-drop context of the source and target, and check if they belong to the same context. This helps in scenarios involving multiple drag-and-drop contexts. ```csharp Debug.WriteLine($"Source context: {DragDrop.GetDragDropContext(dragInfo.VisualSource)}"); Debug.WriteLine($"Target context: {DragDrop.GetDragDropContext(dropInfo.VisualTarget)}"); Debug.WriteLine($"Same context: {dropInfo.IsSameDragDropContextAsSource}"); ``` -------------------------------- ### IDragInfo.MouseButton Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets which mouse button initiated the drag. ```APIDOC ## MouseButton Property Gets which mouse button initiated the drag. | Type | Values | Description | |-------------|-----------------|-------------------------| | MouseButton | Left, Right, Middle | Button that started the drag | **Remarks:** Right-button dragging requires `CanDragWithMouseRightButton` property to be enabled. ``` -------------------------------- ### Drop Hint Data Template Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/extension-interfaces.md Defines a DataTemplate for the drop hint adorner. This example displays a simple TextBlock with the text 'Drop items here' in green. ```xml ``` -------------------------------- ### IsSameDragDropContextAsSource Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets whether the target is in the same drag-drop context as the source. ```APIDOC ## IsSameDragDropContextAsSource Property ### Description Gets whether the target is in the same drag-drop context as the source. ### Property Signature ```csharp bool IsSameDragDropContextAsSource { get; } ``` ### Type bool ### Remarks Returns true if the drag-drop contexts match or if both are empty. This property helps prevent drops between controls with different `DragDropContext` property values. ``` -------------------------------- ### Core Data Flow in Drag and Drop Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/INDEX.md Illustrates the sequence of events and interface interactions during a drag-and-drop operation, from initiation to completion. This flow helps understand how the library manages data and visual feedback. ```text User initiates drag ↓ DragInfo created (contains source info) ↓ IDragSource.CanStartDrag() → IDragSource.StartDrag() (set Data & Effects) ↓ Windows DragDrop starts ↓ IDropTarget.DragEnter() → DragOver() (repeatedly) ↓ (User sets IDropInfo: Data, Effects, DropTargetAdorner) ↓ Drop occurs ↓ IDropTarget.Drop() (insert items, update collection) ↓ IDragSource.Dropped() (remove items if move) ``` -------------------------------- ### Apply Custom DropInfoBuilder in XAML Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/extension-interfaces.md Demonstrates how to apply a custom IDropInfoBuilder to a control using XAML markup. This allows the control to use the custom logic for drop information creation. ```xml ``` -------------------------------- ### Configure DropTargetInsertionAdorner Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/adorners-and-visual-feedback.md Configures the drop target to use an insertion adorner, which displays a line indicating the precise insertion point. Customizes the adorner's brush and pen. ```csharp // Set the insertion adorner dropInfo.DropTargetAdorner = DropTargetAdorners.Insert; // Customize the brush and pen DragDrop.SetDropTargetAdornerBrush(target, Brushes.Blue); DragDrop.SetDropTargetAdornerPen(target, new Pen(Brushes.DarkBlue, 2)); ``` ```xml ``` -------------------------------- ### VisualTargetFlowDirection Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the flow direction (LeftToRight or RightToLeft) of the target. ```APIDOC ## VisualTargetFlowDirection Property ### Description Gets the flow direction (LTR or RTL) of the target. ### Method `FlowDirection VisualTargetFlowDirection { get; }` ### Parameters #### Property - **VisualTargetFlowDirection** (FlowDirection) - Readonly - Text direction (LeftToRight, RightToLeft). ``` -------------------------------- ### DropHintState Enumeration Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/types.md Represents the visual state of drop hint feedback. Use 'Active' for valid targets and 'Error' for invalid ones. ```csharp public enum DropHintState { None, // Default state, no special highlighting Active, // Over a valid drop target Error // Over an invalid drop target } ``` ```csharp public void DragOver(IDropInfo dropInfo) { if (CanAcceptItem(dropInfo.Data)) { dropInfo.DropTargetHintState = DropHintState.Active; dropInfo.Effects = DragDropEffects.Move; } else { dropInfo.DropTargetHintState = DropHintState.Error; dropInfo.Effects = DragDropEffects.None; } } ``` -------------------------------- ### Configure DropTargetHintAdorner Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/adorners-and-visual-feedback.md Enables and configures the drop target hint adorner, which provides visual cues before a drag operation begins. Allows setting custom hint text and adorner states. ```csharp // Enable drop hints DragDrop.SetUseDropTargetHint(target, true); // Set hint text DragDrop.SetDropHintText(target, "Drag items here"); // Set hint adorner and state dropInfo.DropTargetHintAdorner = DropTargetAdorners.Hint; dropInfo.DropTargetHintState = DropHintState.Active; ``` ```xml ``` -------------------------------- ### VisualTargetFlowDirection Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the flow direction (LeftToRight or RightToLeft) of the target. ```csharp FlowDirection VisualTargetFlowDirection { get; } ``` -------------------------------- ### DataObject Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets or sets the IDataObject used for the drag operation. ```APIDOC ## DataObject Property ### Description Gets or sets the IDataObject used for the drag. Advanced usage. ### Property `object DataObject { get; set; }` ### Parameters N/A ### Return Value - **object** - Custom IDataObject instance ### Remarks Rarely needed. Set to provide custom data formats on the clipboard during drag. ``` -------------------------------- ### Insertion Line Feedback Configuration Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/configuration-and-scenarios.md Configures a drop target to display an insertion line indicating where items will be placed. It also allows the insertion line adorner to be shown always. ```xml ``` -------------------------------- ### InsertPosition Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the relative position where items will be inserted compared to TargetItem. ```APIDOC ## InsertPosition Property ### Description Gets the relative position where items will be inserted compared to `TargetItem`. ### Property Signature ```csharp RelativeInsertPosition InsertPosition { get; } ``` ### Type RelativeInsertPosition ### Remarks Possible values: TopLeft, TopRight, BottomLeft, BottomRight, TargetItemCenter. Indicates the insert position relative to the target item. ``` -------------------------------- ### Enable Copy with Ctrl Key Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/API-OVERVIEW.md Configures the drag-and-drop operation to perform a copy when the Control key is held down. Set the DragDropCopyKeyState attached property to ControlKey. ```xml ``` -------------------------------- ### VisualTargetOrientation Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the layout orientation (Horizontal or Vertical) of the target control. ```APIDOC ## VisualTargetOrientation Property ### Description Gets the layout orientation of the target control. ### Method `Orientation VisualTargetOrientation { get; }` ### Parameters #### Property - **VisualTargetOrientation** (Orientation) - Readonly - Primary layout direction (Horizontal, Vertical). ``` -------------------------------- ### TargetGroup Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the group category under the cursor, if the target uses grouping. ```APIDOC ## TargetGroup Property ### Description Gets the group category under the cursor (if target uses grouping). ### Method `CollectionViewGroup TargetGroup { get; }` ### Parameters #### Property - **TargetGroup** (CollectionViewGroup) - Readonly - Group under cursor, or null. ``` -------------------------------- ### Implement Batch Drop Processing Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/configuration-and-scenarios.md Collects dropped items over a short period and processes them as a batch using a DispatcherTimer. ```csharp public class BatchOperationHandler : DefaultDropHandler { private List _batch = new(); private DispatcherTimer _batchTimer; public override void Drop(IDropInfo dropInfo) { var items = ExtractData(dropInfo.Data); _batch.AddRange(items); // Process batch after delay _batchTimer?.Stop(); _batchTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(0.5) }; _batchTimer.Tick += (s, e) => { ProcessBatch(_batch); _batch.Clear(); _batchTimer.Stop(); }; _batchTimer.Start(); } private void ProcessBatch(List items) { // Implement batch operation } } ``` -------------------------------- ### IDropHintInfo Interface Definition Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/types.md Defines the contract for objects providing information for drop hint display. This interface is used to configure the adorner and text for drop hints. ```csharp public interface IDropHintInfo { IDragInfo DragInfo { get; } Type DropTargetHintAdorner { get; set; } string DropHintText { get; set; } DropHintState DropTargetHintState { get; set; } } ``` -------------------------------- ### DropPosition Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the current mouse cursor position relative to the VisualTarget. ```APIDOC ## DropPosition Property ### Description Gets the current mouse cursor position relative to the `VisualTarget`. ### Method `Point DropPosition { get; }` ### Parameters #### Property - **DropPosition** (Point) - Readonly - Coordinates within target element. ``` -------------------------------- ### VisualTargetOrientation Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the layout orientation of the target control (Horizontal or Vertical). ```csharp Orientation VisualTargetOrientation { get; } ``` -------------------------------- ### Register UseDropTargetHintProperty Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/dragdrop-attached-properties.md Enables or disables the drop hint feature, which visualizes potential drop targets before a drop occurs. This property is attached to a DependencyObject. ```csharp public static readonly DependencyProperty UseDropTargetHintProperty = DependencyProperty.RegisterAttached("UseDropTargetHint", typeof(bool), typeof(DragDrop), new PropertyMetadata(default(bool))); public static bool GetUseDropTargetHint(DependencyObject element) public static void SetUseDropTargetHint(DependencyObject element, bool value) ``` -------------------------------- ### TargetGroup Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the group category under the cursor, if the target uses grouping. ```csharp CollectionViewGroup TargetGroup { get; } ``` -------------------------------- ### DropPosition Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the current mouse cursor position relative to the VisualTarget. ```csharp Point DropPosition { get; } ``` -------------------------------- ### Set Drop Target Hint State in DragOver Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/adorners-and-visual-feedback.md Dynamically sets the drop target hint state based on whether the data can be accepted, providing visual feedback to the user. ```csharp public void DragOver(IDropInfo dropInfo) { if (CanAcceptData(dropInfo)) { dropInfo.DropTargetHintState = DropHintState.Active; dropInfo.Effects = DragDropEffects.Move; } else { dropInfo.DropTargetHintState = DropHintState.Error; dropInfo.Effects = DragDropEffects.None; } } ``` -------------------------------- ### DragDropCopyKeyState Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the keyboard modifier that triggers copy mode for this drag. ```APIDOC ## DragDropCopyKeyState Property ### Description Gets the keyboard modifier that triggers copy mode for this drag. ### Property `DragDropKeyStates DragDropCopyKeyState { get; }` ### Parameters N/A ### Return Value - **DragDropKeyStates** - ControlKey, ShiftKey, AltKey, or None ### Remarks Set via `DragDrop.DragDropCopyKeyStateProperty` attached property on the source element. ``` -------------------------------- ### Configure Drag Info Builder Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/dragdrop-attached-properties.md Use the DragInfoBuilderProperty to specify a custom builder for creating IDragInfo objects. This is useful for third-party control support. The default value is null. ```csharp public static readonly DependencyProperty DragInfoBuilderProperty = DependencyProperty.RegisterAttached("DragInfoBuilder", typeof(IDragInfoBuilder), typeof(DragDrop)); public static IDragInfoBuilder GetDragInfoBuilder(DependencyObject element) public static void SetDragInfoBuilder(DependencyObject element, IDragInfoBuilder value) ``` -------------------------------- ### DragDropHandler Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets or sets the function that performs the Windows drag-and-drop operation. ```APIDOC ## DragDropHandler Property ### Description Gets or sets the function that actually performs the Windows drag-and-drop operation. Advanced usage. ### Property `Func DragDropHandler { get; set; }` ### Parameters N/A ### Return Value - **Func** - Drag-drop function (Default: `System.Windows.DragDrop.DoDragDrop`) ``` -------------------------------- ### Enable Drag-Drop Between Windows Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/configuration-and-scenarios.md Configures ListBoxes in separate windows to support drag-and-drop operations between them using a shared 'Global' drag-drop context. ```xml ``` -------------------------------- ### Implement Logging for DragOver and Drop Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/configuration-and-scenarios.md Extend DefaultDropHandler to log drag-over and drop events. This is useful for debugging and understanding the flow of drag-and-drop operations. ```csharp public class LoggingDropHandler : DefaultDropHandler { public override void DragOver(IDropInfo dropInfo) { Debug.WriteLine($"DragOver: Source={dropInfo.DragInfo?.VisualSource?.GetType()?.Name}"); base.DragOver(dropInfo); Debug.WriteLine($" Effects={dropInfo.Effects}"); } public override void Drop(IDropInfo dropInfo) { Debug.WriteLine($"Drop: {dropInfo.Data?.GetType()?.Name} -> {dropInfo.InsertIndex}"); base.Drop(dropInfo); } } ``` -------------------------------- ### IDragInfo.SourceIndex Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the position of the single dragged item in its source collection. ```APIDOC ## SourceIndex Property Gets the position of the single dragged item in its source collection. ```csharp int SourceIndex { get; } ``` | Type | Description | |------|-------------------------| | int | Zero-based index, or -1 if not found | ``` -------------------------------- ### IDragInfo.SourceCollection Property Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-info.md Gets the bound collection on the source control, if it's an ItemsControl. ```APIDOC ## SourceCollection Property Gets the bound collection on the source control (if it's an ItemsControl). ```csharp IEnumerable SourceCollection { get; } ``` | Type | Description | |-------------|-------------------------------------| | IEnumerable | Bound items source, or null if unbound | **Remarks:** - Null if `VisualSource` is not bound to a collection - Useful for move operations to remove items from source ``` -------------------------------- ### ShouldCopyData Static Method Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/api-reference/drag-drop-handlers.md Determines if a drop operation should be a copy (Ctrl key pressed) or a move. Considers configured key states. ```csharp public static bool ShouldCopyData(IDropInfo dropInfo) ``` -------------------------------- ### DragDrop Class Source: https://github.com/punker76/gong-wpf-dragdrop/blob/develop/_autodocs/API-OVERVIEW.md The `DragDrop` class serves as the static entry point for configuring drag-and-drop behavior using attached properties and accessing default handlers. ```APIDOC ## DragDrop Class ### Description The `DragDrop` class is the main entry point for the framework, providing static methods and properties to configure drag-and-drop behavior on UI elements and access default handlers. ### Class Signature ```csharp public static partial class DragDrop ``` ### Attached Properties - `IsDragSourceProperty` (DependencyProperty) - Configures an element as a drag source. - `IsDropTargetProperty` (DependencyProperty) - Configures an element as a drop target. - `DragHandlerProperty` (DependencyProperty) - Assigns a custom drag handler to an element. - `DropHandlerProperty` (DependencyProperty) - Assigns a custom drop handler to an element. ### Static Methods - `GetIsDragSource(DependencyObject element)` - Retrieves the `IsDragSource` property value. - `SetIsDragSource(DependencyObject element, bool value)` - Sets the `IsDragSource` property value. - `GetIsDropTarget(DependencyObject element)` - Retrieves the `IsDropTarget` property value. - `SetIsDropTarget(DependencyObject element, bool value)` - Sets the `IsDropTarget` property value. - `GetDragHandler(DependencyObject element)` - Retrieves the `DragHandler` property value. - `SetDragHandler(DependencyObject element, IDragSource value)` - Sets the `DragHandler` property value. - `GetDropHandler(DependencyObject element)` - Retrieves the `DropHandler` property value. - `SetDropHandler(DependencyObject element, IDropTarget value)` - Sets the `DropHandler` property value. ### Default Handlers - `DefaultDragHandler` (IDragSource) - The default drag source handler implementation. - `DefaultDropHandler` (IDropTarget) - The default drop target handler implementation. ### Other Properties - `DataFormat` (DataFormat) - Specifies the default data format for drag-and-drop operations. ```