1

I had creating a new boolean in my user control(WorkflowContainer ) called IsDragMouseOver.

public static DependencyProperty IsDragMouseOverProperty = DependencyProperty.Register("IsDragMouseOver", typeof(bool), typeof(WpfWorkflowBaseDesigner), null);

    public bool IsDragMouseOver
    {
        get
        {
            return (bool)GetValue(IsDragMouseOverProperty);
        }
        set
        {
            SetValue(IsDragMouseOverProperty, value);
        }
    }


    protected override void OnDragEnter(DragEventArgs e)
    {
        base.OnDragEnter(e);
        IsDragMouseOver = true;
    }

    protected override void OnDragOver(DragEventArgs e)
    {
        base.OnDragOver(e);
        IsDragMouseOver = true;
    }


    protected override void OnDrop(DragEventArgs e)
    {
        base.OnDrop(e);
        IsDragMouseOver = false;
    }

    protected override void OnDragLeave(DragEventArgs e)
    {
        base.OnDragLeave(e);
        IsDragMouseOver = false;
    }

I want to display blue sign plus on child element of user control when i drag over in scope of UserControl: enter image description here

that work fine only i drag over on user control but when i drag over on child element IsDragMouseOver return false and blue sign plus not display: enter image description here

code xaml of child element:

 <Path Stretch="Fill" Width="12" Height="12" VerticalAlignment="Center" HorizontalAlignment="Center" StrokeThickness="0.5" Stroke="{DynamicResource BorderBrush}" Panel.ZIndex="1" Fill="Green" Margin="0 0 2 0"
          Visibility="{Binding IsDragMouseOver, RelativeSource={RelativeSource AncestorType={x:Type wfb:Workflow}}, Converter={StaticResource BoolToVisibilityConverter}}"
          Data="M4.1561281,2.2702953 L4.8524521,2.2702954 4.8509674,3.963097 5.8969377,3.9630803 5.8969378,5.0916036 4.8524628,5.1061913 4.8524521,6.7843885 4.1561281,6.7843887 4.1559771,5.0877741 3.1116421,5.0916036 3.1116421,3.9630803 4.1556735,3.9654722 4.1561281,2.2702953 z"/>

How to display sign plus when i drag over inside scope of UserControl and only disable sign plus when drag over outside scope of UserControl ?

Luke Le
  • 728
  • 1
  • 9
  • 24
  • Have you tried to set [IsHitTestVisible="false"](http://stackoverflow.com/q/4226770/1997232) for child? – Sinatr May 13 '16 at 08:47
  • @Sinatr, thanks for reply, i don't to set IsHitTestVisible="false" because it would lose all other events on child and there are so many child elements – Luke Le May 13 '16 at 08:49
  • This is what I expect you will answer. Then you have to handle mouse events (drag events specifically) in the child too to get combined `IsDragMouseOver` result for user control. – Sinatr May 13 '16 at 08:51
  • It may be enough to simply use [`PreviewDragEnter`](https://msdn.microsoft.com/en-us/library/system.windows.dragdrop.previewdragenter(v=vs.100).aspx) (which should be arised in `UserControl` before children receive `DragEnter`). I am not good at tunneling/bubbling understanding and tend to do it *winforms-way*. – Sinatr May 13 '16 at 08:59
  • @Sinatr, thanks for help me, I handle DragEnter in the child too to get combined IsDragMouseOver of user control and set it is true. now it worked as I expected – Luke Le May 13 '16 at 09:15
  • Glad it works. Consider to add your solution as an answer for future readers (I wasn't able to find duplicate of your question). – Sinatr May 13 '16 at 09:21

1 Answers1

0

handle DragEnter in the child element, code sample:

 protected override void OnDragEnter(DragEventArgs e)
        {
            base.OnDragEnter(e);
            WorkflowContainer workflowContainer = DesignerHelper.FindAncestor<WorkflowContainer>(e.OriginalSource as DependencyObject);
            if (workflowContainer != null)
            {
                workflowContainer.IsDragMouseOver = true;
            }
        }
Luke Le
  • 728
  • 1
  • 9
  • 24