Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContextMenu loses DataContext when DpiAwareness is activated #2172

Rand-Random opened this issue Nov 8, 2019 · 4 comments


Copy link

@Rand-Random Rand-Random commented Nov 8, 2019


<Window x:Class="WpfApp1.MainWindow"
        DataContext="{Binding RelativeSource={RelativeSource Self}}">
            <MenuItem Header="{Binding HelloWorld}" />

Code behind:

using System.Windows;

namespace WpfApp1
    public partial class MainWindow : Window
        public string HelloWorld { get; set; } = "Hello World";

        public MainWindow()


<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">

  <application xmlns="urn:schemas-microsoft-com:asm.v3">
      <dpiAwareness xmlns="">PerMonitorV2</dpiAwareness>
      <dpiAware xmlns="">true</dpiAware>


Right mouse click on the window and you will see a context menu with the header "Hello World".

Right mouse click again on the window and you will see a blank menu item.

You can endlessly repeat the right click, and the context menu will stay blank. The important part is that you don't force close the contextmenu, by left mouse click or a click on the menuitem it self, so you have to make sure to right click on an empty space while the context menu is open.

If you remove the app.manifest dpiAwareness settings you will always get the "Hello World", the error happens in both .net Core 3.0 and .net Framework 4.8. It is also present in earlier .net Framework Version the lowest we have tested is .net Framework 4.7.

It also only happens on our Windows 10 machines.

You can "prevent" the error from happening if you left mouse click in between the right mouse clicks.


This comment has been minimized.

Copy link

@vatsan-madhavan vatsan-madhavan commented Nov 8, 2019

We recently fixed a bug in ContextMenu that could be related to this - see #2098.

Can you try this with .NET Core 3.1 daily bits from


This comment has been minimized.

Copy link

@Rand-Random Rand-Random commented Nov 11, 2019

Yes, the problem was indeed related and the PR fixed my issue aswell.

Do you happen to know if this fix will ever make its way back to .net Framework?
I am asking since our app is still running on 4.7, I just tested .net core 3.0 to make sure its still broken, we have no plan to make the switch.


This comment has been minimized.

Copy link

@vatsan-madhavan vatsan-madhavan commented Nov 11, 2019

It will be fixed in 4.8 likely sometime early next year, although I can't give you a definite timeframe. I didn't think that it was a problem in 4.7, but nevertheless I don't expect us to fix it in anything older than .NET 4.8 under normal circumstances.

Note that I'm referring to versions of the installed .NET framework runtime - this discussion is agnostic of whatever version of .NET the application has targeted at build-time (i.e, the TFM). A PMAv2 app with TFM=4.7 running on .NET 4.8 runtime could encounter this problem.

BTW, WPF really doesn't support PMAv2 prior to .NET 4.8 runtime. That said, it doesn't prevent the use of PMAv2 by applications willing to handle window-messages (especially DPI related messages) on their own. That having been said, if you do have a repro on .NET 4.7.x, I would think that you can repro it both on PMAv2 on PMAv1 - so this particular point (re PMAv2 being supported only on .NET 4.8) may prove to be a red-herring in the context of this bug.

Are you sure that you are seeing this problem on .NET Framework runtimes older than 4.8?


This comment has been minimized.

Copy link

@Rand-Random Rand-Random commented Nov 12, 2019

You were correct I was merley talking about the target framework my application is build to, but not about the runtime that is actually installed on my machines.

I therefor can only verify that I am getting the mentioned problem on Windows 10 with .net Framework 4.8 installed.

Sorry for the confusion.

Thanks for sharing the information about the time frame, I wasn't sure if .net framework would still get bug fixes, cause of the .net 5 approach, and thought that it would only get security fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.