Click here to Skip to main content
15,878,748 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am unable to disable if I use WindowChrome.WindowChrome style. Please let me know your input to resolve this problem. Without WindowChrome, I am able to disable context menu with the same piece of code.

What I have tried:

<Window x:Class="ConextMenu_Sample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" WindowStyle="None">
    <WindowChrome.WindowChrome>
        <WindowChrome CaptionHeight="35"
                      CornerRadius="0"
                      ResizeBorderThickness="5"
                      UseAeroCaptionButtons="False" 
         />
    </WindowChrome.WindowChrome>
    <Window.Resources>

    </Window.Resources>
    <Grid>

    </Grid>
</Window>
public partial class MainWindow : Window
    {
        private const uint WP_SYSTEMMENU = 0x02;
        private const uint WM_SYSTEMMENU = 0xa4;
        public MainWindow()
        {
            InitializeComponent();
            Loaded += OnLoaded;
        }

        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            IntPtr windIntPtr = new WindowInteropHelper(this).Handle;
            HwndSource hwndSource = HwndSource.FromHwnd(windIntPtr);
            hwndSource.AddHook(new HwndSourceHook(WndProc));
        }

        private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam, ref bool handled)
        {
            if ((msg == WM_SYSTEMMENU) && (wparam.ToInt32() == WP_SYSTEMMENU))
            {
                handled = true;
            }
            return IntPtr.Zero;
        }        
    }              
Posted
Updated 13-Mar-17 22:29pm

1 solution

This Google search: wpf disable window context menu - Google Search[^] has many solutions for you including this one: wpf - Disable the whole Context Menu - Stack Overflow[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900