WPF Context Menu Click issue RRS feed

  • Question

  • I have created WPF user control to load into the Excel taskpane. When I click the first menu item in the context menu, the event is getting triggered. However, the event is not getting triggered for the other menu item. The code is as follows:

        <UserControl x:Class="Controls.TabBrowser"
                     MinHeight="25" MinWidth="500" MaxWidth="1265">
            <Grid x:Name="MyGrid">
        <Button Name="MyButton" Content="Click" Width="100" HorizontalAlignment="Left" PreviewMouseRightButtonDown="MyButton_PreviewMouseRightButtonDown">
                                    <MenuItem Name="cmDuplicateWB" Click="cmDuplicateWB_Click"  ToolTip="Duplicate the selected workbook" Header="Duplicate" Icon="Save"/>
                                    <MenuItem Name="cmRenameWB" Click="cmRenameWB_Click" ToolTip="Rename the selected workbook" Header="Rename" Icon="Save" Tag="F2"/>
                                    <MenuItem Name="cmShowFolder" Click="cmShowFolder_Click" ToolTip="Open the file in the file explorer" Header="Show in Folder" Icon="Save"/>   

        using System.Windows.Controls;
        using System.ComponentModel;
        using System;
        using System.Windows;
        using System.Windows.Input;
        namespace Controls
            /// <summary>
            /// Interaction logic for TabBrowser.xaml
            /// </summary>
            public partial class TabBrowser : UserControl, INotifyPropertyChanged
                public TabBrowser()
                private void cmDuplicateWB_Click(object sender, RoutedEventArgs e)
                private void cmRenameWB_Click(object sender, RoutedEventArgs e)
                    private void cmShowFolder_Click(object sender, RoutedEventArgs e)
                        MessageBox.Show("Show in Folder");
            private void MyButton_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)


    Saturday, June 18, 2016 4:59 PM

All replies

  • Hi,

    I have a test and it works correctly.

    I am using win10 64bit with office2016 64bit and VS2015Enterprise.

    I am using the same codes as you and here are my steps:

    1. Add Reference System.Xaml (or I will get 3 errors: The type name 'IComponentConnector' could not be found in the namespace 'System.Windows.Markup'.)
    2. Add a User Control(WPF)
    3. Build
    4. Add a User Control
    5. Drag the User Control(WPF) from toolbox to the designer of the task pane
    6. Rebuild

    So could you share us how you add your User Control, I suggest you to test User Control in other application like winform to check if there are any problems.



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, June 20, 2016 8:29 AM
  • Hello Vijay,

    Are you able to reproduce the issue with a regular Windows Forms application?


    Monday, June 20, 2016 10:58 AM