Start RadDocking drag programmatically

2 Answers 25 Views
Docking DragAndDrop
Jack
Top achievements
Rank 1
Jack asked on 07 Dec 2021, 02:21 PM

Hi there,

We have a situation where we're creating dockable panes and we'd like to make it so when you hit the button to make one it will create it and start a drag option automatically so you can then dock it where you want as soon as you make it, is this doable at all? I haven't been able to find anything online about it

Thanks

2 Answers, 1 is accepted

Sort by
0
Stenly
Telerik team
answered on 08 Dec 2021, 02:33 PM

Hello Jack,

When creating the pane programmatically, you could call its MakeFloatingDockable method, which will set it in a floating state and will allow the user to dock it at the desired position. The following snippet shows a sample pane initialization in a button Click event.

private void RadButton_Click(object sender, RoutedEventArgs e)
{
    RadPane pane = new RadPane();
    pane.Header = "Physics";
    this.scienceGroup.Items.Add(pane);
    pane.MakeFloatingDockable();
}

Please note that when creating the pane, you would need to add it inside a RadPaneGroup, otherwise, the pane would be created. You could refer to this article that explains the behavior of the control when a pane is in a floating state.

With that said, I have prepared a sample project, so, could you give it a try and let me know whether this approach works for you?

Regards,
Stenly
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Jack
Top achievements
Rank 1
commented on 08 Dec 2021, 04:25 PM

Thanks for the help, I already had that behaviour implemented, what we wanted to do additionally was to make it so when it is created it is in a dragging state such that you click the button then automatically are dragging it so you can select where you want it to appear
0
Stenly
Telerik team
answered on 13 Dec 2021, 01:13 PM

Hello Jack,

To achieve the wanted behavior, you could utilize the DragBehavior.BeginDrag static method and as parameters, pass the ToolWindow of the created pane and the position of the mouse relative to the RadDocking control instance. The following code snippet shows the code block from my previous reply, modified to include this logic:

private void RadButton_Click(object sender, RoutedEventArgs e)
{
    this.pane = new RadPane();
    pane.Header = "Physics";
    this.scienceGroup.Items.Add(pane);
    pane.MakeFloatingDockable();

    var window = pane.GetParentToolWindow();
    var point = Mouse.GetPosition(this.docking);
    window.Top = point.Y;
    window.Left = point.X;
    DragBehavior.BeginDrag(window, point, false);
}

With this said, I have attached a sample project for you to test, so, could you give it a try?

Regards,
Stenly
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Docking DragAndDrop
Asked by
Jack
Top achievements
Rank 1
Answers by
Stenly
Telerik team
Share this question
or