Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7968431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:04:35+00:00 2026-06-04T07:04:35+00:00

I have a resource dictionary inside which I have a context menu: <ResourceDictionary x:Class=MyApp.Components.MyContextMenu

  • 0

I have a resource dictionary inside which I have a context menu:

<ResourceDictionary x:Class="MyApp.Components.MyContextMenu"
                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:MyApp"
                    xmlns:components="clr-namespace:MyApp.Components">
    <ContextMenu ContextMenuOpening="OnContextMenuOpening">

and the resource dictionary XAML has this code behind:

using System;
using System.Windows;
using System.Windows.Controls;

namespace MyApp.Components
{
    public partial class MyContextMenu : ResourceDictionary
    {
        public MyContextMenu()
        {
            InitializeComponent();
        }  

        void OnContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            Console.WriteLine("here i am!");
        }
    }
}

The log is not appearing. I wonder why the event is not firing or getting to the right place — is the problem because I have wrapped the context menu inside this resource dictionary?

Update: Interestingly if I remove the code-behind function, I get an error during compilation:

does not contain a definition for ‘ContextMenu_OnContextMenuOpening’
and no extension method ‘ContextMenu_OnContextMenuOpening’ accepting a
first argument of type ‘MyApp.Components.MyContextMenu’ could be found
(are you missing a using directive or an assembly reference?)

Update 2: Looks like that both Console.WriteLine and Debug.WriteLine produce output, but only “randomly” and especially when I’m clicking near the bottom of the item. Some sort of collision detection not working maybe?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:04:36+00:00Added an answer on June 4, 2026 at 7:04 am

    It is a bug in the framework: http://connect.microsoft.com/VisualStudio/feedback/details/353112/contextmenu-opening-event-doesnt-fire-properly

    A contextmenu’s opening event doesn’t fire on the first right click.
    It only fires when you do two sequential right clicks while not moving
    the mouse.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a created a resource dictionary as <ResourceDictionary x:Class=RPK.WindowsResources xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:vm=clr-namespace:RPK.ViewModel xmlns:vw=clr-namespace:RPK.View
I have a DataTemplate inside a global/shared ResourceDictionary like this which targets a DataType:
Consider the following XAML file: <Window x:Class=ExpressionVisualizer.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:sle=clr-namespace:System.Linq.Expressions;assembly=System.Core Title=MainWindow Height=350 Width=525> <Window.Resources>
I have a resource dictionary in my WPF application which contains the style information
I have a Resource Dictionary in which I have defined styles and control templates
Resource dictionary 03-11-2010 10:56 AM | I have two different projects. I linked a
Say I have a resource (e.g. a filehandle or network socket) which has to
I have a custom Control which contains the generic.xaml inside the Themes folder. I
How can I have my merged resource dictionary live outside of the xap file
I have a scenario where I parse the XAML of the resource dictionary at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.