So, how to assign a single click event to the menu items of a dynamically created menu.
5 Answers, 1 is accepted
Due to time constraints I wasn't able to work up any good sample code, but here's the idea...
Check out this link from the documentation for loading XML data to the menu:
void RadMenuItem_Click(object sender, RoutedEventArgs e)
And in that function you do custom logic based on the header of the sender.
Not sure if anyone else has done something like this and has code (or a better suggestion), just throwing out my first idea when I read this post. Still getting used to Silverlight/WPF so I'm always looking for better ways to handle things. :)
RadControls for Silverlight 2 support RoutedEvents so this mean that you can handle event at some parent.
Let say that you have RadMenu with ItemsSource. That way you don't have the RadMenuItems (they are dynamically created when needed) so you can't add handler to Click event.
But you can add handler on RadMenu because RadMenuItem.Click event is routed event that bubbles (go from RadMenuItem to the Page/Root element).
Here is how you can attach handler in code from RadMenuItem.Click event.
AddHandler is extension method so you will need the commented usings (using Telerik.Windows).
The cast from RouthedEventArgs to RadRouthedEventArgs is needed because RouthedEventArgs OriginalSource is readonly and the handler for Click event is of RoutedEventHandler type (we may change the delegate in future).
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.