Skip to content

Commit 6b19d25

Browse files
author
KB Bot
committed
Added new kb article navigationview-drag-drop-customize
1 parent 7697ab4 commit 6b19d25

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---
2+
title: Preventing Nested Drag and Drop in NavigationView Pages
3+
description: Learn how to prevent nested drag and drop and pin a footer page in the RadNavigationView for UI for WinForms.
4+
type: how-to
5+
page_title: How to Avoid Nested Drag and Pin Footer Page in RadNavigationView
6+
meta_title: How to Avoid Nested Drag and Pin Footer Page in RadNavigationView
7+
slug: navigationview-drag-drop-customize
8+
tags: navigationview, ui-for-winforms, drag-drop, footer, custom-drag-drop-service
9+
res_type: kb
10+
ticketid: 1691649
11+
---
12+
13+
|Product Version|Product|Author|
14+
|----|----|----|
15+
|2025.2.520|RadGridView for WinForms|[Dinko Krastev](https://www.telerik.com/blogs/author/dinko-krastev)|
16+
17+
## Description
18+
19+
I am dynamically adding pages to the [RadNavigationView](https://docs.telerik.com/devtools/winforms/controls/navigationview/overview) control. I want users to reorder pages by dragging and dropping them without creating nested pages. All pages should remain in a single level. Additionally, I need a footer page pinned to the bottom that cannot be dragged or have other pages dropped below it or into it.
20+
21+
## Solution
22+
23+
To achieve this, create a custom drag-and-drop service and override specific methods. Follow these steps:
24+
25+
1. **Prevent Nested Dragging and Dropping:**
26+
Implement a custom class that derives from `RadPageViewDragDropService`. Override the `CanDragOver` method to restrict drop positions and prevent nested pages.
27+
28+
````C#
29+
public class CustomDragDropService : RadPageViewDragDropService
30+
{
31+
public CustomDragDropService(RadPageViewElement owner) : base(owner)
32+
{
33+
}
34+
35+
protected override bool CanDragOver(RadPageViewItem pageViewItem)
36+
{
37+
if (!(pageViewItem is RadPageViewNavigationViewItem radPageViewNavigationViewItem))
38+
{
39+
return true;
40+
}
41+
42+
if (!radPageViewNavigationViewItem.Enabled || !radPageViewNavigationViewItem.AllowDrop)
43+
{
44+
return false;
45+
}
46+
47+
if (radPageViewNavigationViewItem.PinPosition == NavigationViewItemPinPosition.Footer)
48+
{
49+
return false;
50+
}
51+
52+
DropPosition dropPosition = GetDropPosition(radPageViewNavigationViewItem, base.DropLocation);
53+
if (dropPosition == DropPosition.AsChildNode)
54+
{
55+
return false;
56+
}
57+
58+
return base.CanDragOver(pageViewItem);
59+
}
60+
61+
protected internal virtual DropPosition GetDropPosition(RadPageViewNavigationViewItem radPageViewNavigationViewItem, Point dropLocation)
62+
{
63+
int num = radPageViewNavigationViewItem.Size.Height / 3;
64+
int y = dropLocation.Y;
65+
if (y < num)
66+
{
67+
return DropPosition.BeforeNode;
68+
}
69+
70+
if (y >= num && y <= num * 2)
71+
{
72+
return DropPosition.AsChildNode;
73+
}
74+
return DropPosition.AfterNode;
75+
}
76+
}
77+
78+
````
79+
80+
2. **Disable Dragging for Footer Page:**
81+
Override the `OnPreviewDragStart` method to check the `PinPosition` property. Cancel the drag operation for the footer page.
82+
83+
````C#
84+
85+
protected override void OnPreviewDragStart(PreviewDragStartEventArgs e)
86+
{
87+
var radPageViewNavigationViewItem = e.DragInstance as RadPageViewNavigationViewItem;
88+
if (radPageViewNavigationViewItem != null)
89+
{
90+
if (radPageViewNavigationViewItem.PinPosition == NavigationViewItemPinPosition.Footer)
91+
{
92+
e.CanStart = false;
93+
}
94+
}
95+
base.OnPreviewDragStart(e);
96+
}
97+
98+
````
99+
100+
3. **Assign Custom Drag-and-Drop Service:**
101+
Set the custom service to the RadNavigationView control.
102+
103+
````C#
104+
105+
radNavigationView1.NavigationViewElement.ItemDragService = new CustomDragDropService(radNavigationView1.NavigationViewElement);
106+
107+
````
108+
109+
## See Also
110+
111+
* [RadNavigationView Overview Documentation](https://docs.telerik.com/devtools/winforms/controls/navigationview/overview)
112+
* [RadPageViewDragDropService API Reference](https://docs.telerik.com/devtools/winforms/api/html/T_Telerik_WinControls_UI_RadPageViewDragDropService.htm)

0 commit comments

Comments
 (0)