Marcus Lambert
Top achievements
Rank 1
Marcus Lambert
asked on 05 Oct 2009, 06:31 PM
Hi,
Is there a way to add a context menu to a row in the grid via xaml only without using the row loaded event.
Can you add it in a row template?
Thanks
Marcus
Is there a way to add a context menu to a row in the grid via xaml only without using the row loaded event.
Can you add it in a row template?
Thanks
Marcus
5 Answers, 1 is accepted
0
Hi Marcus,
You can add the menu for the entire grid and check current row in ItemClick event using GetClickedElement<>() method. Here is an example:
<grid:RadGridView x:Name="RadGridView1">
<nav:RadContextMenu.ContextMenu>
<nav:RadContextMenu ItemClick="RadContextMenu_ItemClick">
<nav:RadContextMenu.Items>
<nav:RadMenuItem Header="Item 1"/>
<nav:RadMenuItem Header="Item 2"/>
<nav:RadMenuItem Header="Item 3"/>
</nav:RadContextMenu.Items>
</nav:RadContextMenu>
</nav:RadContextMenu.ContextMenu>
</grid:RadGridView>
...
private void RadContextMenu_ItemClick(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
var row = ((RadContextMenu) sender).GetClickedElement<GridViewRow>();
}
All the best,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
You can add the menu for the entire grid and check current row in ItemClick event using GetClickedElement<>() method. Here is an example:
<grid:RadGridView x:Name="RadGridView1">
<nav:RadContextMenu.ContextMenu>
<nav:RadContextMenu ItemClick="RadContextMenu_ItemClick">
<nav:RadContextMenu.Items>
<nav:RadMenuItem Header="Item 1"/>
<nav:RadMenuItem Header="Item 2"/>
<nav:RadMenuItem Header="Item 3"/>
</nav:RadContextMenu.Items>
</nav:RadContextMenu>
</nav:RadContextMenu.ContextMenu>
</grid:RadGridView>
...
private void RadContextMenu_ItemClick(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
var row = ((RadContextMenu) sender).GetClickedElement<GridViewRow>();
}
All the best,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Marcus Lambert
Top achievements
Rank 1
answered on 06 Oct 2009, 10:43 PM
Thanks for that, but is there a way just to have the context menu appear on row right click and not for the wholw grid. ? as you may wany different menus on other part of the grid.
Marcus
Marcus
0
Accepted
Hello Marcus,
You can use Opened event to achieve your goal. Here is an example of how to show the menu for data rows only (without header row):
private void RadContextMenu_Opened(object sender, RoutedEventArgs e)
{
var row = ((RadContextMenu) sender).GetClickedElement<GridViewRow>();
if (row == null)
{
((RadContextMenu) sender).IsOpen = false;
}
}
All the best,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
You can use Opened event to achieve your goal. Here is an example of how to show the menu for data rows only (without header row):
private void RadContextMenu_Opened(object sender, RoutedEventArgs e)
{
var row = ((RadContextMenu) sender).GetClickedElement<GridViewRow>();
if (row == null)
{
((RadContextMenu) sender).IsOpen = false;
}
}
All the best,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Alex
Top achievements
Rank 1
answered on 31 Mar 2010, 12:26 AM
Hi, I'm also trying to get a context menu to show up in my Silverlight 4 test app, but I can only ever get the default "Silverlight" context menu (That brings up the Silverlight Options)
Here is the xaml I'm using:
I can not get it to work on neither the grid or the gridview :S
I can make it work if I use different EventNames, however, any of the right mouse button events will not work
The only way I could get it to open was to manually intercept the RadGridView1_MouseRightButtonDown event, and force an menu.IsOpen = true; But then it still has the default context menu if you right click again (on the grid and not on the context menu)
Here is the xaml I'm using:
<UserControl x:Class="Test_ContextMenu.MainPage" |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
mc:Ignorable="d" |
d:DesignHeight="600" d:DesignWidth="800" |
xmlns:Navigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" |
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" |
> |
<Grid> |
<Navigation:RadContextMenu.ContextMenu> |
<Navigation:RadContextMenu ItemClick="RadContextMenu_ItemClick" Opened="RadContextMenu_Opened"> |
<Navigation:RadContextMenu.Items> |
<Navigation:RadMenuItem Header="Add" /> |
<Navigation:RadMenuItem Header="Edit" /> |
<Navigation:RadMenuItem Header="Delete" /> |
</Navigation:RadContextMenu.Items> |
</Navigation:RadContextMenu> |
</Navigation:RadContextMenu.ContextMenu> |
<telerik:RadGridView x:Name="RadGridView1" Margin="12" MouseRightButtonDown="RadGridView1_MouseRightButtonDown"> |
<Navigation:RadContextMenu.ContextMenu> |
<Navigation:RadContextMenu ItemClick="RadContextMenu_ItemClick" Opened="RadContextMenu_Opened"> |
<Navigation:RadContextMenu.Items> |
<Navigation:RadMenuItem Header="Add" /> |
<Navigation:RadMenuItem Header="Edit" /> |
<Navigation:RadMenuItem Header="Delete" /> |
</Navigation:RadContextMenu.Items> |
</Navigation:RadContextMenu> |
</Navigation:RadContextMenu.ContextMenu> |
</telerik:RadGridView> |
</Grid> |
</UserControl> |
I can not get it to work on neither the grid or the gridview :S
I can make it work if I use different EventNames, however, any of the right mouse button events will not work
The only way I could get it to open was to manually intercept the RadGridView1_MouseRightButtonDown event, and force an menu.IsOpen = true; But then it still has the default context menu if you right click again (on the grid and not on the context menu)
0
Hello Alexander Sun,
Greetings,
Milan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
If you would like to open RadcontextMenu on right-click the Silverlight pluging should run in Windoless mode. Could you please take a look at this help topic.
Greetings,
Milan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.