Truely nasty code

5 posts, 1 answers
  1. Dennis
    Dennis avatar
    5 posts
    Member since:
    May 2009

    Posted 26 May 2009 Link to this post

    Nasty code alert...
                menu.AddHandler(RadMenuItem.ClickEvent, new RoutedEventHandler(OnMenuItemClick));


          private static void OnMenuItemClick(object sender, RoutedEventArgs e)
          {
             RadMenuItem menu = e.OriginalSource as RadMenuItem;
    ...

    Do you think this works?

    nonono.

             RadMenuItem menu = ((RadRoutedEventArgs)e).OriginalSource as RadMenuItem;

    works :S Someone didnt get the message about inheritance :S

    and guess if this would work:

                menu.AddHandler(RadMenuItem.ClickEvent, new RadRoutedEventHandler(OnMenuItemClick));

    That would make it typesafe... but nonono, they have this check:

    internal bool IsLegalHandler(Delegate handler)
    {
        Type type = handler.GetType();
        if (type != this.HandlerType)
        {
            return (type == typeof(RoutedEventHandler));
        }
        return true;
    }

    Good thing with reflector, because the error message when actually trying to do this says absolutely nothing.

  2. Answer
    Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 27 May 2009 Link to this post

    Hi Dennis,

    You are right. Handling the menu items' Click event really sucks and I apologize for that. The good news is that with SP2 (released today) we added ItemClick event on RadMenu and RadContextMenu:

    <telerikNavigation:RadMenu ItemClick="OnItemClick" ... />

    private void OnItemClick(object sender, RadRoutedEventArgs args)
    {
        RadMenuItem item = args.OriginalSource as RadMenuItem;
        ...
    }

    Sincerely yours,
    Valeri Hristov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
  4. Dennis
    Dennis avatar
    5 posts
    Member since:
    May 2009

    Posted 27 May 2009 Link to this post

    Great :)

    Now finding it was a challenge :(

    http://www.telerik.com/account/free-trials.aspx has 1 version (1.526)
    http://www.telerik.com/account/downloads/internal-builds.aspx has two version (1.508 and 1.501)
    http://www.telerik.com/account/downloads/internal-builds.aspx?type=2&mvid=2009&pid=571 has no versions

  5. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 27 May 2009 Link to this post

    Hello Dennis,

    The version you need is 2009.1.526 (this means Q1 2009, built on May 26). I will post a feature request to the guys who develop and maintain the website about improvements in the internal builds page. Btw, how did you get on the last page? I was unable to find a link to the internal builds with parameters...

    Sincerely yours,
    Valeri Hristov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Dennis
    Dennis avatar
    5 posts
    Member since:
    May 2009

    Posted 27 May 2009 Link to this post

    The third link is on the page with the first link
Back to Top
DevCraft banner