WPF / C #: disable drag and drop for text fields?

Does anyone have an idea how I can disable Drag and Drop for all my TextBox elements? I found something here , but I will need to run a loop for all the elements.

+3
source share
4 answers

You can easily wrap the description of this article in an attached property / behavior ...

T. TextBoxManager.AllowDrag = "False" (For more information, check out these two CodeProject articles - Drag and Drop Example and Example Glass Effect Link Text )

Blend SDK Behaviors

UPDATE

  • kek444 , textbxo !
+1

InitializeComponent()

DataObject.AddCopyingHandler(textboxName, (sender, e) => { if (e.IsDragDrop) e.CancelCommand(); });
+3

ex MyTextBox: TextBox :

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

    protected override void OnDrop(DragEventArgs e)
    {
        e.Handled = true;
    }


    protected override void OnDragOver(DragEventArgs e)
    {
        e.Handled = true;
    }
0

TextBox, , :

/// <summary>
/// Represents a <see cref="TextBox"/> control that does not allow drag on its contents.
/// </summary>
public class NoDragTextBox:TextBox
{
    /// <summary>
    /// Initializes a new instance of the <see cref="NoDragTextBox"/> class.
    /// </summary>
    public NoDragTextBox()
    {
        DataObject.AddCopyingHandler(this, NoDragCopyingHandler);
    }

    private void NoDragCopyingHandler(object sender, DataObjectCopyingEventArgs e)
    {
        if (e.IsDragDrop)
        {
            e.CancelCommand();
        }
    }
}

TextBox : NoDragTextBox, "local" NoDragTextBox. / TextBox.

http://jigneshon.blogspot.be/2013/10/c-wpf-snippet-disabling-dragging-from.html

0

Source: https://habr.com/ru/post/1712668/


All Articles