How do I prevent WPF buttons from remaining highlighted after being clicked?

后端 未结 7 1702
灰色年华
灰色年华 2021-02-06 21:44

When a standard WPF button is clicked, it gets highlighted in blue (probably using the blue color from whatever Windows theme is set), and it stays highlighted until you interac

7条回答
  •  深忆病人
    2021-02-06 22:10

    I found 2 steps solution. The solution is little funny but working . My referance posts are;

    How to remove global FocusVisualStyle to all the Controls?

    and C# WPF application .NET 4.5 Set Mouse Position

    One DLL must be imported , because WPF is not directly supporting mouse cursor move.

    1. add System.Runtime.InteropServices to namespace
    2. Add two line to the MainWindow or whatever your window's code

    [DllImport("User32.dll")] private static extern bool SetCursorPos(int X, int Y);

    1. Add these 2 lines to your click event . SetCursorPos(0, 0); ButtonName.FocusVisualStyle = null;

    It works for me .

提交回复
热议问题