Skip to content

Fix setting VisualStylesMode to Classic in the Properties window - #15019

Open
LeafShi1 wants to merge 2 commits into
dotnet:mainfrom
LeafShi1:Fix_15012_VisualStylesMode_cannot_be_changed_to_Classic
Open

Fix setting VisualStylesMode to Classic in the Properties window#15019
LeafShi1 wants to merge 2 commits into
dotnet:mainfrom
LeafShi1:Fix_15012_VisualStylesMode_cannot_be_changed_to_Classic

Conversation

@LeafShi1

@LeafShi1 LeafShi1 commented Sep 1, 2026

Copy link
Copy Markdown
Member

Fixes #15012

Root Cause

The VisualStylesMode setter removed the local value when it matched the parent’s resolved mode. In the designer, setting Classic matched the ambient parent value, so the override was removed and the property reverted to Inherit.

Proposed changes

  • Only remove the local override when VisualStylesMode.Inherit is explicitly assigned. Preserve explicitly assigned values even when they currently match the parent.

Customer Impact

  • Customers can configure VisualStylesMode as Classic through the Visual Studio Properties window. Explicit values also remain stable if the parent’s visual styles mode later changes.

Regression?

  • No

Risk

  • Minimal

Screenshots

Before

Selecting Classic for Form.VisualStylesMode in the Properties window immediately reverted the property to Inherit and did not serialize the selection.

BeforeChanges.mp4

After

Selecting Classic preserves and serializes the explicit value. Selecting Inherit continues to remove the local override as expected.

AfterChanges.mp4

Test methodology

  • Unit test and manual test

Test environment(s)

  • .net 11.0.0-rc.1.26424.125
Microsoft Reviewers: Open in CodeFlow

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR adjusts Control.VisualStylesMode’s ambient/local override behavior so that explicitly assigning a value (e.g., Classic) remains a local override even when it matches the current parent-resolved value, fixing WinForms Designer property-grid reversion/serialization for Classic.

Changes:

  • Update Control.VisualStylesMode setter to only clear the local value when VisualStylesMode.Inherit is explicitly assigned.
  • Add a unit test that uses PropertyDescriptor.SetValue to validate that setting a value matching the parent preserves ShouldSerializeValue.
File summaries
File Description
src/System.Windows.Forms/System/Windows/Forms/Control.cs Changes the VisualStylesMode setter’s logic for when to remove the local override.
src/test/unit/System.Windows.Forms/System/Windows/Forms/ControlTests.VisualStylesMode.cs Adds a regression test covering property-grid style setting when the value matches the parent.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/System.Windows.Forms/System/Windows/Forms/Control.cs
@LeafShi1
LeafShi1 force-pushed the Fix_15012_VisualStylesMode_cannot_be_changed_to_Classic branch from 4006e82 to fac2b0b Compare September 1, 2026 08:31
@LeafShi1
LeafShi1 force-pushed the Fix_15012_VisualStylesMode_cannot_be_changed_to_Classic branch from fac2b0b to e9e04ac Compare September 2, 2026 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Form.VisualStylesMode cannot be changed from Inherit to Classic in the VS properties window

2 participants