Context menus

6 posts, 1 answers
  1. Marcus Lambert
    Marcus Lambert avatar
    41 posts
    Member since:
    Aug 2009

    Posted 05 Oct 2009 Link to this post

    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
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 06 Oct 2009 Link to this post

    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.
  3. DevCraft banner
  4. Marcus Lambert
    Marcus Lambert avatar
    41 posts
    Member since:
    Aug 2009

    Posted 06 Oct 2009 Link to this post

    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
  5. Answer
    Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 08 Oct 2009 Link to this post

    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.
  6. Alex
    Alex avatar
    141 posts
    Member since:
    Mar 2010

    Posted 30 Mar 2010 Link to this post

    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:

    <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)
  7. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 31 Mar 2010 Link to this post

    Hello Alexander Sun,

    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.
Back to Top
DevCraft banner