views:

27

answers:

1

I have the following piece of XAML code:

<controlsInputToolkit:ContextMenuService.ContextMenu>
    <controlsInputToolkit:ContextMenu
                        Height="75"                                
                        Width="200"                                
                        IsOpen="False"
                        Visibility="Collapsed"
                        Closed="mnuPopup_Closed"
                        x:Name="mnuPopup">

        <controlsInputToolkit:MenuItem
                            x:Name="mnuAnswer911Call"
                            Header="Answer Call"
                            Click="mnuAnswer911Call_Click"
                            IsEnabled="True"/>

        <controlsInputToolkit:MenuItem
                            x:Name="mnuHangup911Call"
                            Header="Hangup call"
                            Click="mnuHangup911Call_Click"
                            IsEnabled="True"/>

        <controlsInputToolkit:MenuItem
                            x:Name="mnuConference911Call"
                            Header="Conference Call"
                            Click="mnuConference911Call_Click"
                            IsEnabled="False"/>
    </controlsInputToolkit:ContextMenu>
</controlsInputToolkit:ContextMenuService.ContextMenu>

How do I add a bunch of extra menu items on the fly? I've tried:

        MenuItem mi = new MenuItem();
        mi.Header = "Yeah";
        mi.Visibility = System.Windows.Visibility.Visible;
        mi.Click += new RoutedEventHandler(mi_Click);
        mnuPopup.Items.Add(mi); 

but the new menu does actually appear at all. What am I missing?

+1  A: 

The Silverlight Context Menu does not support submenus yet. But there are open source alternatives to help you achieve this. Here is one:

www.sl4popupmenu.codeplex.com

Ziad