开发者

Silverlight 4 and the ContextMenu control

开发者 https://www.devze.com 2023-01-11 09:51 出处:网络
I have the following piece of XAML code: <controlsInputToolkit:ContextMenuService.ContextMenu> <controlsInputToolkit:ContextMenu

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"
                      开发者_如何学C      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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消