This is a migrated thread and some comments may be shown as answers.

Need to disallow the drag operation while within popup on RadListBoxItem

4 Answers 24 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Nathan
Top achievements
Rank 1
Nathan asked on 12 Mar 2014, 10:01 PM
I've got a RadListBox, and each item in it has a ToggleButton that opens a Popup that's defined in each of the list box items; so the Popup isn't shared between the items.  These Popups contain controls for data entry like textboxes, checkboxes, etc.  When the user clicks and drags their mouse within the Popup, the drag operation for the containing RadListBoxItem starts.  This can happen in the background of the popup or when trying to select some text within some other control in the Popup, like a TextBox.

I'd like to completely stop the drag operation from ever starting when I've got this Popup open.

What's the best way to accomplish this?

4 Answers, 1 is accepted

Sort by
0
Polya
Telerik team
answered on 17 Mar 2014, 04:36 PM
Hello Nathan,

I would suggest disabling the RadListBox.DragDropBehavior by setting it to null when the Popup opens and then reinitialize it with a new ListBoxDragDropBehavior ( or the previously saved ListBoxDragDropBehavior ) when the Popup closes.
You can achieve that by handling the Opened and Closed events of the Popup:

private ListBoxDragDropBehavior listBoxDragDropBehavior;
 
private void Popup_Opened(object sender, EventArgs e)
{
    listBoxDragDropBehavior = this.listBox1.DragDropBehavior;
    this.listBox1.DragDropBehavior = null;
}
 
private void Popup_Closed(object sender, EventArgs e)
{
    this.listBox1.DragDropBehavior = listBoxDragDropBehavior;
}

Hopefully this helps.

Regards,
Polya
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
0
Nathan
Top achievements
Rank 1
answered on 17 Mar 2014, 06:31 PM
I tried this, and it doesn't fix the problem, but it does change the behavior.  

I also tried just using a RadListBox, with no drag and drop behavior specified at all.  And I have some problem with it as well.  When the popup is open trying to select text, or click and drag within the popup seems to activate a drag and drop operation, but it doesn't actually change the ordering when the drop happens.  And this is when I have NO drag and drop behavior specified on the RadListBox.

This works great with a normal ListBox.

I've got a project that demonstrates the problem (found here https://dl.dropboxusercontent.com/u/3583840/ProgrammingSolutions/TelerikDragAndDropTest.zip); at least using the Q1 2014 release.  It has two list boxes, each using the exact same data template for the items.  Clicking the button on each item will open a popup with a textbox.  Try selecting the text in that popup by holding down the mouse and dragging the cursor to select a word.  In the vanilla ListBox this works great.  In the RadListBox it does not.







0
Accepted
Polya
Telerik team
answered on 18 Mar 2014, 02:03 PM
Hello Nathan,

Thank you for providing the project. It clarifies the situation better.
The reason behind the issue is that the Popup is a part of every RadListBoxItem in the RadListBox and   the AllowCapturedDrag of the DragDropManager is enabled in the RadListBoxItemStyle:

<Setter Property="telerik:DragDropManager.AllowCapturedDrag" Value="True" />

So when we try to select the text in the TextBox of the Popup, DragInitialize of the RadListBoxItem is called.
In order to disable this behavior we need to set the AllowCapturedDrag of the RadListBox and every RadListBoxItem when the Popup is opened and enable it when the Popup closes:

private void Popup_Opened(object sender, EventArgs e)
{
    listBoxDragDropBehavior = this.RadListBox.DragDropBehavior;
    this.RadListBox.DragDropBehavior = null;
    this.RadListBox.SetValue(DragDropManager.AllowCapturedDragProperty, false);
    foreach (var item in this.RadListBox.Items)
    {
        RadListBoxItem t = this.RadListBox.ItemContainerGenerator.ContainerFromItem(item) as RadListBoxItem;
        t.SetValue(DragDropManager.AllowCapturedDragProperty, false);
    }
}
 
private void Popup_Closed(object sender, EventArgs e)
{
    this.RadListBox.DragDropBehavior = listBoxDragDropBehavior;
    this.RadListBox.SetValue(DragDropManager.AllowCapturedDragProperty, true);
    foreach (var item in this.RadListBox.Items)
    {
        RadListBoxItem t = this.RadListBox.ItemContainerGenerator.ContainerFromItem(item) as RadListBoxItem;
        t.SetValue(DragDropManager.AllowCapturedDragProperty, true);
    }
}

Hopefully this approach will resolve the issue. Looking forward to your response.

Regards,
Polya
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
0
Nathan
Top achievements
Rank 1
answered on 25 Mar 2014, 08:28 PM
Thanks Polya, that did it!
Tags
DragAndDrop
Asked by
Nathan
Top achievements
Rank 1
Answers by
Polya
Telerik team
Nathan
Top achievements
Rank 1
Share this question
or