What event to handle item click ?

14 posts, 0 answers
  1. NS
    NS avatar
    179 posts
    Member since:
    Jan 2007

    Posted 07 Oct 2008 Link to this post

    Hello,
    Eg, I have a root menu called: "Root"
    Root Contains two RadMenuItems (Sub1 and Sub2)

    What event must I trigger to get what I've clicked in the menu ? eg, I hover to Sub1 and I click on that.

    After clicking on Sub 1 I want to do something like: this.Content = new Sub1();
  2. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 08 Oct 2008 Link to this post

    Hello Nicolas,

    RadMenuItem have Click event. You can handle it like this:

    Sub1.Click += new RoutedEventHandler(OnSub1Click);     
    private void OnSub1Click(object sender, RoutedEventArgs e)     
    {     
       // you can do something here.     
    }    
     

    If you need more help, do not hesitate to contact us.

    Best wishes,
    Hristo
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. DevCraft banner
  4. kevin
    kevin avatar
    2 posts
    Member since:
    Oct 2008

    Posted 21 Oct 2008 Link to this post

    I want to handle the click event on menu control.
    But I am not able to find the Click Event..
    can any one help me...?

    Kevin

  5. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 21 Oct 2008 Link to this post

    Hi Kevin,

    The Click event is a routed event which means that it will travel down the visual tree from the MenuItem to the application's VisualRoot. It can be handled on any control along the way. Here is how you handle routed events:

    public MyDemo()    
            {    
                InitializeComponent();    
        
                menu1.AddHandler(RadMenuItem.ClickEvent, new RoutedEventHandler(MenuItemClick));    
            }    
        
            private void MenuItemClick(object sender, RoutedEventArgs args)    
            {    
                RadMenuItem item = args.OriginalSource as RadMenuItem;    
            }    
     

    Please note that you need to have the "Telerik.Windows" using to see the extensions methods related to handling the events.

    Routed events can save a lot of time in a larger application because they allow you to handle events witout having to go through each individual object to sign up for them.

    Here is a blog post on the routed events:

    http://blogs.telerik.com/HristoHristov/Posts/08-07-23/Routed_Events_in_Silverlight_2.aspx?ReturnURL=%2fHristoHristov%2fPosts.aspx

    Let us know if you need more questions!


    Best wishes,
    Valentin.Stoychev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Eric Schoenholzer
    Eric Schoenholzer avatar
    138 posts
    Member since:
    Mar 2004

    Posted 21 Oct 2008 Link to this post

    The last example didn't work for me.

    args.OriginalSource is null.

    I have to use the parameter 'sender'.

     (or use "RadRoutedEventArgs args = e as RadRoutedEventArgs;" for casting the arguments, as seen in other post).

    Thanks

    Eric

  7. yelong
    yelong avatar
    28 posts
    Member since:
    Aug 2006

    Posted 12 Nov 2008 Link to this post


    If the menu contains submenus, looks that Click event doesn't fire on the parent menu.

    I had used MouseLeftButtonUp event as the work arround. but it doesn't work anymore with your last 2 releases.

    Any workaround? I need to capture the Clicke event for the parent menu itselft.

    Thanks,

    Yelong
  8. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 13 Nov 2008 Link to this post

    Hi Yelong,

    I cannot reproduce your problem. Can you povide a sample code where Click event doesn't work?
    Thanks.


    Best wishes,
    Hristo
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  9. yelong
    yelong avatar
    28 posts
    Member since:
    Aug 2006

    Posted 13 Nov 2008 Link to this post

     

    Hi there,

    Thanks for you reply.

     

    You can test the link below 
    http://silverlight.services.live.com/invoke/66026/Debug%20Project%20for%20Telerik/iframe.html

    and download the source code below

    http://cid-f9a9a74fc4058aff.skydrive.live.com/self.aspx/Public/MyPublicFolder/SLDebugProject.zip

    Let me know if you still can not reproduce the issue.

    Thanks,

    Yelong

  10. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 14 Nov 2008 Link to this post

    Hello Yelong,

    Thanks for the provided example.

    We ran it locally and everything worked as expected.

    When I clicked a MenuItem the RadMenu's Click event was fired and Alert window popped. The Alert window is a modal window, which means that you cannot click other controls until you close that window (the alert window).

    When zooming the MapControl an exception appeared, however it did not seem to be related to our controls. We have not stated that we support such third party controls. We will continue our research on the matter and if the problem appears to be somehow related to our controls we will surely fix it right away.

    Greetings,
    Hristo
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  11. yelong
    yelong avatar
    28 posts
    Member since:
    Aug 2006

    Posted 14 Nov 2008 Link to this post


    :((

    1. When you click the menu -- "Click doesn't work", you can get the popup window?
    For anyone is reading this post,  could you help to test if it works in your environment from the link?
    http://silverlight.services.live.com/invoke/66026/Debug%20Project%20for%20Telerik/iframe.html

    2. For map control, as I said, it works with your previous release.
    That's why I have posted the issue here and I am not able to upgrade to your latest.

    Thanks,

  12. Serrin
    Serrin avatar
    286 posts
    Member since:
    Sep 2008

    Posted 14 Nov 2008 Link to this post

    I can confirm that the menu is working on my side, using latest everything on my machine right down to Silverlight tools. :)

    And I've crashed the map on their own demos as well, doesn't happen all the time, but I know this isn't the first time that map control took out my entire browser. :(
  13. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 17 Nov 2008 Link to this post

    Hi All,

    regarding the telerik controls - the issues has been fixed - please test them with the release that is coming out this week.

    Let us know how it goes.

    Sincerely yours,
    Valentin.Stoychev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  14. BlogReader
    BlogReader avatar
    27 posts
    Member since:
    Apr 2009

    Posted 22 Sep 2009 Link to this post

    I second yelong. The Click event is not fired if the MenuItem has other MenuItems in it.
  15. BlogReader
    BlogReader avatar
    27 posts
    Member since:
    Apr 2009

    Posted 22 Sep 2009 Link to this post

    I just realized that in order for the event to be raised for header items, we need to set the NotifyOnHeaderClick property to True.
Back to Top
DevCraft banner