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

ContextMenu for just the "Pane" part of the NavigationView

2 Answers 139 Views
NavigationView (Hamburger Menu)
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 2
Iron
Iron
Veteran
Joe asked on 07 Apr 2021, 05:07 PM
I use a RadNavigationView for my whole application.  I whipped up a context menu for it that I set on it.  But I want my context menu to only appear when the user right-clicks on the "Pane" part of the RadNavigationView -- the part on the left, not for the content part on the right.  How may I do this? 

I tried looking at the visual structure of the control template to see if there is some sort of distinct control representing just the pane whose "ContextMenu" property I could set but I could not spot anything.

I really do not want to redefine the whole ControlTemplate.

Any ideas?

2 Answers, 1 is accepted

Sort by
0
Joe
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 08 Apr 2021, 12:54 AM
I was under a time crunch so in order to make this work, I was forced to completely redefine the RadNavigationView's template.  I copied the ControlTemplate from the Telerik theme XAML files and added one single context menu property to PART_PaneRoot.

Would still like to know if there is a simpler way to do this though.
0
Martin Ivanov
Telerik team
answered on 12 Apr 2021, 08:51 AM

Hello Joe,

An alternative approach would be to subscribe to define the context menu on the RadNavigationView level. Then subscribe to the menu's Opening event and check the element under the mouse. If the PART_PaneRoot element is not clicked, handle the event. This will cancel the opening. For example:

private void RadContextMenu_Opening(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
	var menu = (RadContextMenu)sender;
	var owner = menu.GetClickedElement<FrameworkElement>();
	var paneRoot = GetRootGrid(owner);
	if (paneRoot == null)
	{
		e.Handled = true;
	}
}

private static Grid GetRootGrid(FrameworkElement origin)
{
	var grid = origin.ParentOfType<Grid>();
	while (grid != null && grid.Name != "PART_PaneRoot")
	{
		grid = grid.ParentOfType<Grid>();
	}
	return grid;
}
 I've attached a small example showing this approach. I hope it helps.

Regards,
Martin Ivanov
Progress Telerik

Тhe web is about to get a bit better! 

The Progress Hack-For-Good Challenge has started. Learn how to enter and make the web a worthier place: https://progress-worthyweb.devpost.com.

Tags
NavigationView (Hamburger Menu)
Asked by
Joe
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Joe
Top achievements
Rank 2
Iron
Iron
Veteran
Martin Ivanov
Telerik team
Share this question
or