This is a migrated thread and some comments may be shown as answers.

Truely nasty code

4 Answers 77 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Dennis
Top achievements
Rank 1
Dennis asked on 27 May 2009, 03:42 AM
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.

4 Answers, 1 is accepted

Sort by
0
Accepted
Valeri Hristov
Telerik team
answered on 27 May 2009, 08:09 AM
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.
0
Dennis
Top achievements
Rank 1
answered on 27 May 2009, 09:37 AM
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

0
Valeri Hristov
Telerik team
answered on 27 May 2009, 09:55 AM
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.
0
Dennis
Top achievements
Rank 1
answered on 27 May 2009, 10:40 AM
The third link is on the page with the first link
Tags
Menu
Asked by
Dennis
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Dennis
Top achievements
Rank 1
Share this question
or