Context menu in CS file

7 posts, 0 answers
  1. ruty
    ruty avatar
    42 posts
    Member since:
    Mar 2009

    Posted 26 Mar 2009 Link to this post

    Hi,
    I want to create context menu in cs file.(not in xaml file)
    all your exampels in the web site for context menu this in xaml files.
    i write:
     RadContextMenu radContextMenu1 = new RadContextMenu();  
                radContextMenu1.ClickToOpen = true;  
                radContextMenu1.EventName = "Click";  
                firstLevel = new RadMenuItem();  
                firstLevel.Header = "aa";  
                firstLevel.Icon = new Image() { Source = new BitmapImage(new Uri("no-drag.png", UriKind.Relative)) };  
                firstLevel.Click += new RoutedEventHandler(firstLevel_Click);  
                firstLevel.SubmenuClosed += new RoutedEventHandler(firstLevel_SubmenuClosed);  
                (firstLevel_SubmenuOpened);  
                radContextMenu1.Items.Add(firstLevel); 
     and the context menu don't show on the screen.
    How I do it????
  2. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 26 Mar 2009 Link to this post

    Hello Ruty,

    The context menu needs to be set as an attached property to the element that should be his parent. To set attached properties in code, the similarly-named static methods are used, in your case you need to add:

    RadContextMenu.SetContextMenu(someVisualElement, radContextMenu1); 

    Where someVisualElement can be any visual element that exposes an event with the chosen name.

    Greetings,
    Miroslav
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. DevCraft banner
  4. ruty
    ruty avatar
    42 posts
    Member since:
    Mar 2009

    Posted 30 Mar 2009 Link to this post

    Thanks,
    I do it, but i get error "click event can not be found".
    my code is:

     RadContextMenu buttonContextMenu = new RadContextMenu();  
                        buttonContextMenu.EventName = "Click";  
                        RadMenuItem item1 = new RadMenuItem()  
                        {  
                            Header = "Statuses" 
                        };  
                        RadMenuItem item11 = new RadMenuItem()  
                        {  
                            Header = "Open" 
                        };  
                        item1.Items.Add(item11);  
                        RadMenuItem item12 = new RadMenuItem()  
                        {  
                            Header = "New" 
                        };  
                        item1.Items.Add(item12);  
                        RadMenuItem item13 = new RadMenuItem()  
                        {  
                            Header = "Cancelled" 
                        };  
                        item1.Items.Add(item13);  
                        buttonContextMenu.Items.Add(item1);  
     RadContextMenu.SetContextMenu(taskRectangle, buttonContextMenu);  
     
    can you help me????
    Thanks.
  5. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 30 Mar 2009 Link to this post

    Hello ruty,

    The EventName should be event that exist on the element that you attach the context menu.
    From your code it looks like you are attaching it to Rectange. The rectangle doesn't have Click event. This is why you receive this error. For the rectangle you can you MouseLeftButtonDown or MouseLeftButtonUp events.

    Let us know if you need more information.

    All the best,
    Hristo
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  6. ruty
    ruty avatar
    42 posts
    Member since:
    Mar 2009

    Posted 30 Mar 2009 Link to this post

    Thanks,
    Your answer  help me.
    I want to ask more question:
    I want to set contexet menu when the user click on right button mouse.
    It is possible in telerik???
    Thanks.
  7. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 31 Mar 2009 Link to this post

    Hi ruty,

    Yes it is possible but you need to run your Silverlight application in windowless mode. Just add the bold line in the silverlight object tag (your html or aspx page).

    <div id="silverlightControlHost">  
        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">  
            <param name="source" value="ClientBin/SilverlightApplication31.xap"/>  
            <param name="onerror" value="onSilverlightError" /> 
            <param name="background" value="white" /> 
            <param name="minRuntimeVersion" value="2.0.31005.0" /> 
            <param name="autoUpgrade" value="true" /> 
            <param name="windowless" value="true" /> 
            <href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;">  
                <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>  
            </a> 
        </object> 
        <iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe> 
    </div> 

    You don't need to change the EventName - the default value (MouseRightButtonDown) will do the job.
    Let us know if you need more help.

    Regards,
    Hristo
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  8. Joshua Huang
    Joshua Huang avatar
    5 posts
    Member since:
    Jul 2009

    Posted 21 Sep 2009 Link to this post

    Hi,
    I am having problem with the radcontextmenu mouse right click as well. I can have the mouse left click, mouse over, or fired by isOpen=true work to show the context menu. But the mouse right click just never working, even if I use windowless. Please help. Thanks!
Back to Top
DevCraft banner