Need to disallow the drag operation while within popup on RadListBoxItem

5 posts, 1 answers
  1. Nathan
    Nathan avatar
    12 posts
    Member since:
    Dec 2011

    Posted 12 Mar 2014 Link to this post

    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?
  2. Polya
    Admin
    Polya avatar
    200 posts

    Posted 17 Mar 2014 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Nathan
    Nathan avatar
    12 posts
    Member since:
    Dec 2011

    Posted 17 Mar 2014 in reply to Polya Link to this post

    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.







  5. Answer
    Polya
    Admin
    Polya avatar
    200 posts

    Posted 18 Mar 2014 Link to this post

    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.

     
  6. Nathan
    Nathan avatar
    12 posts
    Member since:
    Dec 2011

    Posted 25 Mar 2014 in reply to Polya Link to this post

    Thanks Polya, that did it!
Back to Top
UI for WPF is Visual Studio 2017 Ready