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

后端 未结 7 1780
灰色年华
灰色年华 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:06

    I needed to do something similar, but in code at runtime, it looked like this

    //You can get this XAML by using System.Windows.Markup.XamlWriter.Save(yourButton.Template)";
                 const string controlXaml = "" +
                                        "" +
                                        "" +
                                        "" +
                                        "" +
                                        "True" +
                                        "True" +
                                        "" +
                                        "True" +
                                        "True" +
                                        "#FFADADAD" +
                                        "False" +
                                        "";
    
            var xamlStream = new MemoryStream(System.Text.Encoding.Default.GetBytes(controlXaml));
            var _buttonControlTemplate = (ControlTemplate)System.Windows.Markup.XamlReader.Load(xamlStream);
            var yourButton = new Button() { Template = _buttonControlTemplate };
    

    You can see that i comment the ""RenderMouseOver" line

    My first hope was using FrameworkElementFactory but i needed to create all the default template.... ALL BY HAND! ;)
    Using

    System.Windows.Markup.XamlWriter.Save(myButton.Template)
    

    It give me the template i wanted and then removing the Render section was easy.

提交回复
热议问题