Skip to content

Commit

Permalink
Merge pull request #2191 from cwensley/curtis/wpf-drag-drop-textbox
Browse files Browse the repository at this point in the history
WIP: Wpf: Fix drag/drop events for controls with intrinsic drop functionality
  • Loading branch information
cwensley authored Apr 24, 2022
2 parents 38f1368 + 3702ba5 commit 1fdc6ca
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
30 changes: 22 additions & 8 deletions src/Eto.Wpf/Forms/WpfFrameworkElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,15 @@ protected sw.Size UserPreferredSize
/// For example, when the user types into a text box, it will grow to fit the content if it is auto sized.
/// This doesn't happen on any other platform, so we need to disable this behaviour on WPF.
/// </summary>
protected virtual bool PreventUserResize { get { return false; } }
protected virtual bool PreventUserResize => false;

public abstract Color BackgroundColor { get; set; }

public virtual bool UseMousePreview { get { return false; } }
public virtual bool UseMousePreview => false;

public virtual bool UseKeyPreview { get { return false; } }
public virtual bool UseKeyPreview => false;

public virtual bool UseDragDropPreview => UseMousePreview;

public sw.Size ParentMinimumSize
{
Expand All @@ -190,7 +192,7 @@ public sw.Size ParentMinimumSize
}
}

public virtual sw.FrameworkElement ContainerControl { get { return Control; } }
public virtual sw.FrameworkElement ContainerControl => Control;

public virtual Size Size
{
Expand Down Expand Up @@ -479,18 +481,30 @@ public override void AttachEvent(string id)
HandleEvent(Eto.Forms.Control.GotFocusEvent);
break;
case Eto.Forms.Control.DragDropEvent:
Control.Drop += Control_DragDrop;
if (UseDragDropPreview)
Control.PreviewDrop += Control_DragDrop;
else
Control.Drop += Control_DragDrop;
break;
case Eto.Forms.Control.DragOverEvent:
Control.DragOver += Control_DragOver;
if (UseDragDropPreview)
Control.PreviewDragOver += Control_DragOver;
else
Control.DragOver += Control_DragOver;
HandleEvent(Eto.Forms.Control.DragLeaveEvent);
break;
case Eto.Forms.Control.DragEnterEvent:
Control.DragEnter += Control_DragEnter;
if (UseDragDropPreview)
Control.PreviewDragEnter += Control_DragEnter;
else
Control.DragEnter += Control_DragEnter;
HandleEvent(Eto.Forms.Control.DragOverEvent);
break;
case Eto.Forms.Control.DragLeaveEvent:
Control.DragLeave += Control_DragLeave;
if (UseDragDropPreview)
Control.PreviewDragLeave += Control_DragLeave;
else
Control.DragLeave += Control_DragLeave;
HandleEvent(Eto.Forms.Control.DragEnterEvent); // need DragEnter so it doesn't get called when going over children
break;
case Eto.Forms.Control.EnabledChangedEvent:
Expand Down
7 changes: 6 additions & 1 deletion test/Eto.Test/Sections/Behaviors/DragDropSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ DataObject CreateDataObject()
LogEvents(gridDest);


var textBoxDest = new TextBox { AllowDrop = true, Text = "TextBox" };
LogEvents(textBoxDest);

var comboBoxDest = new ComboBox { AllowDrop = true, Text = "ComboBox" };
LogEvents(comboBoxDest);

// layout

Expand Down Expand Up @@ -278,7 +283,7 @@ DataObject CreateDataObject()
layout.EndVertical();

layout.BeginVertical(xscale: true);
layout.AddRange("Drag destinations:", buttonDestination, drawableDest);
layout.AddRange("Drag destinations:", buttonDestination, drawableDest, textBoxDest, comboBoxDest);
layout.Add(treeDest, yscale: true);
layout.Add(gridDest, yscale: true);
layout.EndVertical();
Expand Down

0 comments on commit 1fdc6ca

Please sign in to comment.