Windows 10 Creators Update changes the style of PropertyGrid control

后端 未结 3 1458
一向
一向 2020-12-18 02:18

I just upgraded some systems to Windows 10 Creators Update and I noticed that the windows forms PropertyGrid control changed its default visual style for header

相关标签:
3条回答
  • 2020-12-18 02:27

    There's a bug in PropertyGrid:

    The property PropertyGrid.LineColor has a DefaultValue attribute Set to SystemColors.InactiveBorder.
    But the internal field lineColor is initialized with SystemColors.ControlDark.

    This is bad, because the Windows Forms designer detects that the property has the same value as the DefaultValue attribute, and therefore it does not write the designer code for the PropertyGrid.LineColor property in InitializeComponent. So at runtime, the property is initialized to SystemColors.ControlDark.

    As a quick hack, you can set the property after InitializeComponent:

    InitializeComponent();
    propertyGrid.LineColor = SystemColors.InactiveBorder;
    
    0 讨论(0)
  • 2020-12-18 02:29

    This seems to be a "feature". From the .NET Framework 4.7 Release Notes:

    Changed the background color of property grid lines to provide an 8:1 contrast ratio for high contrast themes.

    So, I'd say, no, with Windows 10 Creators Update, there's no way to revert to the old style without recompiling (see this answer).

    I complained here.

    Update

    I refined the PropertyGrid class like this:

    sealed class LightPropertyGrid : PropertyGrid {
        static readonly Color DefaultLineColor = (Color)
            typeof(PropertyGrid)
                .GetProperty(nameof(LineColor))
                .GetCustomAttribute<DefaultValueAttribute>()
                .Value;
    
        public LightPropertyGrid() {
            LineColor = DefaultLineColor;
        }
    }
    

    I'm inferring the initial value for LineColor from the default value defined on the same property. Of course, you can simply assign LineColor = SystemColors.InactiveBorder.

    0 讨论(0)
  • 2020-12-18 02:47

    We are reverting header color to InactiveBorder in the default windows theme in the next release of the .Net Framework, which most likely will be included in the Windows 10 Fall Creators Update. The reason this change was introduced, was that the foreground and background colors were not contrasting enough in one of the High Contrast themes, this is why we are reverting to the previously used color only in the default theme. For your reference, internal work item number, that will be also mentioned in release notes for .Net Framework 4.7.1, is 407249.

    Thank you, Tanya

    0 讨论(0)
提交回复
热议问题