Hi,
I am using Telerik RadTreeView control, I have implemented context menu when i right click for selected treenode,if i right click empty space same context menu displaying.How to remove contextmenu for empty place.
Without your implementation I cannot be sure what is causing the reported behavior behavior. I prepared a sample project that demonstrates how you can implement context menu for each RadTreeViewItem. Basically you can define the context menu for the UI element placed in the ItemTemplate of the RadTreeView.
<TextBlock Text="Context menu item for tree item with Header: "/>
<TextBlock Text="{Binding Title}" />
</TextBlock>
</MenuItem.Header>
</MenuItem>
<MenuItem Header="Item 2" />
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</HierarchicalDataTemplate>
</telerik:RadTreeView.ItemTemplate>
If your context menu is defined for the entire treeview, instead for each item, you can subscribe for the ContextMenuOpening event of the RadTreeView and inside the handler check if the item under the mouse is a RadTreeViewItem, if it's not handle the event. This will prevent displaying the context menu.
var elementUnderMouse = // get item under the mouse cursor position or the RadTreeViewItem which IsMouseOver property is set to True
if (elementUnderMouse is RadTreeViewItem)
{
e.Handled = true;
}
}
Please give the project a try and let me know if it helps. If not, can you please open a new support ticket and send me an isolated project with your implementation. This will help me in better understanding your scenario and assist you further.
Regards,
Martin
Telerik
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.