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

Issues with Dynamic submenu in context menu.

1 Answer 117 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Ganesh
Top achievements
Rank 1
Ganesh asked on 13 Apr 2012, 09:21 AM

We have a RadContextMenu named “ContextMenu” and “miOpen” is RadMenuItem of the context menu, its created in XAML as shown below.

XAML CODE is: -

<telerikNavigation:RadContextMenu.ContextMenu>
<telerikNavigation:RadContextMenu x:Name="ContextMenu" IsOpen="False" Visibility="Collapsed">
<telerikNavigation:RadMenuItem Header="OpenForm" Name="miOpen" Click="miOpen_Click">
<telerikNavigation:RadMenuItem.Icon>
<Image Source="../Images/Open.png" Stretch="None"/>
</telerikNavigation:RadMenuItem.Icon>
</telerikNavigation:RadMenuItem>
</telerikNavigation:RadContextMenu>
</telerikNavigation:RadContextMenu.ContextMenu>

We want to Create SubMenus in “miOpen” at run time dynamically, these submenus items can change at every right click, here is the cs code for dynamic menu creation.
We are using RemoveAt() method as we have to change the SubMenus at every right click (but not in above cs code). 

On First Right Click...above code working good but its giving error “Value does not fall within the expected range” after first rigth click.


Here is CS CODE: -
try
            {
                Telerik.Windows.Controls.RadMenuItem objRadMenuMainMenu =
                          (Telerik.Windows.Controls.RadMenuItem)this.FindName("miOpen");
                for(int k = 0; k<objRadMenuMainMenu.Items.Count;k++)
                {
                    objRadMenuMainMenu.Items.RemoveAt(k);
                }
               
  for (int i = 0; i < 5; i++)
                {
                    Telerik.Windows.Controls.RadMenuItem objConnPart = new           
                                                Telerik.Windows.Controls.RadMenuItem();
                    objConnPart.Header = i.ToString() + "Header";
                    objConnPart.Name = i.ToString() + "Name";
                    objConnPart.Tag = i.ToString() + "Name";
                    objRadMenuMainMenu.Items.Insert(i, objConnPart);                   
                
              ContextMenu.Visibility = Visibility.Visible;
           
            }
 
 catch (Exception ex)
                {
                }

Here are the exception: -

Base exception:

Value does not fall within the expected range. at MS.Internal.XcpImports.CheckHResult(UInt32 hr) at MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, Boolean b) at System.Windows.DependencyObject.SetValue(DependencyProperty property, Boolean b) at System.Windows.Controls.Primitives.Popup.set_IsOpen(Boolean value) at Telerik.Windows.Controls.PopupManager.Open(Popup popup, Boolean attachToVisualRoot) at Telerik.Windows.Controls.PopupManager.OpenPopup(Popup popup, Boolean attachToVisualRoot) at Telerik.Windows.Controls.PopupManager.Open(Popup popup, PopupType type, Boolean attachToVisualRoot) at Telerik.Windows.Controls.PopupWrapper.ShowPopup() at Telerik.Windows.Controls.RadContextMenu.OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue) at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation) at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet) at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value) at Telerik.Windows.Controls.RadContextMenu.set_IsOpen(Boolean value) at Telerik.Windows.Controls.RadContextMenu.TriggerEventFired() at Telerik.Windows.Controls.RadContextMenu.OnEventTriggered(Object sender, EventArgs e) at Telerik.Windows.Controls.RadContextMenu.OnElementWithContextMenuMouseClick(Object sender, MouseButtonEventArgs e) at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args) at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)



Please check above code and give us solution.


Ganesh,
MCL Systems.

 

 

1 Answer, 1 is accepted

Sort by
0
Konstantina
Telerik team
answered on 17 Apr 2012, 03:19 PM
Hello,

You could find more information about how to add dynamically items to the ContextMenu in this help article: http://www.telerik.com/help/silverlight/radcontextmenu-populating-with-data-binding-to-dynamic-data.html

Hope this helps.

Regards,
Konstantina
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Tags
Menu
Asked by
Ganesh
Top achievements
Rank 1
Answers by
Konstantina
Telerik team
Share this question
or