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

Define RadMenuItems dynamically in codebehind

2 Answers 109 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Naseem
Top achievements
Rank 1
Naseem asked on 13 Jan 2011, 03:07 AM
Hello,

I have a RadContextMenu with 2 MenuItems and I need to define SunMenuItems for each of them dynamically in code behind. (because the sub menu items are different based on selected gridview row)

Here is what I have done :

private void BadRawContextMenu_Opened(object sender, RoutedEventArgs e)
        {
            var selItem=((Telerik.Windows.Controls.RadMenuItem)BadRawContextMenu.Items[0]);
  
            selItem.Items.Clear();
  
            selItem.Items.Add(new Telerik.Windows.Controls.RadMenuItem() { Header = "1" });
            selItem.Items.Add(new Telerik.Windows.Controls.RadMenuItem() { Header = "2" });
            selItem.Items.Add(new Telerik.Windows.Controls.RadMenuItem() { Header = "3" });
            selItem.Items.Add(new Telerik.Windows.Controls.RadMenuItem() { Header = "4" });
            selItem.Items.Add(new Telerik.Windows.Controls.RadMenuItem() { Header = "5" });
  
        }

The first time when the contextmenu is opened ,the sub menu show smoothly and fine ,but after first time it doen't display smoothly (I mean with out transition) and even with out border around (please take a look at attached files)
I think it's because of I clearing all the sub items each time by using selItem.Items.Clear();
However I don't know what would be best approach for doing that , I mean for removing sub items and re add them again .

Also I need to mention that I had to change the RadMenuItem Style because I needed it to have scrollbar in it
http://www.telerik.com/community/forums/silverlight/menu/define-listbox-inside-contextmenu.aspx

The second issue comes after couple of times opening context menu and move to sub menus , it gives me bellow error:

Message: Sydtem.InvalidOperationException: Animation target not specified.
at MS.Internal.XcpImports.MethodEx(InPtr,String name,CValue[] cvData)
at MS.Internal.XcpImports.MethodEx(DependencyObject obj ,String name)
at Sydtem.Windows.Media.Animation.Storybord.Begin()
at Telerik.Windows.Controls.Animation.AnimationManager.Play(FrameworkElement target,String animationName,Action CompleteCallback,Object[] args)
at Telerik.Windows.Controls.RadMenuItem.RunExpandAnimation(RadMenuItem menuItem)

I appreciate your help,

Thank you so much,

Kind Regards,
Naseem

2 Answers, 1 is accepted

Sort by
0
Accepted
Hristo
Telerik team
answered on 13 Jan 2011, 01:04 PM
Hi Naseem,

When you remove all items of RadMenuItem we change its template. Then when you add new children we change it again so this may be the reason for the missing animation.
You could try to remove all items except the first one then add the new items and after that to remove the first item. This way the control template of RadMenuItem will not change.

As for the second problem (Animation target not specified) - this problem is fixed in the latest internal build. Please update your binaries to the latest available to resolve the issue.

Let us know if you need further information.

All the best,
Hristo
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Naseem
Top achievements
Rank 1
answered on 13 Jan 2011, 11:46 PM
Hello Hristo ,

Thank you so much for the quick response. Your solution solved my issue :)

Many Thanks ,

Kind Regards,
Naseem
Tags
Menu
Asked by
Naseem
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Naseem
Top achievements
Rank 1
Share this question
or