Background
WinForms has a concept of ambient properties properties that cascade from a parent control to all its children unless a child explicitly overrides the value. The canonical example is DataContext (introduced in .NET 7 via PR #7143), but the pattern also applies to properties like Font, BackColor, ForeColor, Cursor, and BindingContext.
When adding new APIs to WinForms controls, contributors sometimes need to implement ambient properties. The current new-control-api Skill covers standard property patterns but explicitly defers ambient properties to a separate, dedicated Skill.
Motivation
- Standardize the pattern. The existing
DataContext implementation may not fully follow the canonical ambient property approach. A Skill would codify the correct pattern for future APIs.
- Constructor ordering hazard. In WinForms, virtual methods (e.g.,
CreateParams) are called from the base class constructor before the derived class constructor body runs. Ambient properties must handle this safely the Skill should document the pitfalls.
- PropertyStore integration. Ambient properties use
PropertyStore.TryGetValue with a parent-fallback chain. The Skill should prescribe the exact getter/setter pattern, including when to store vs. remove values.
- Propagation pattern. The
OnParent[Property]Changed method must propagate changes to children. The Skill should define the canonical implementation, including disposal guards and child iteration.
- DataContext retrofit. The existing
DataContext implementation should be reviewed against the codified Skill pattern to identify any gaps that should be addressed in .NET 11.
Core Issues to Address in the Skill
Acceptance Criteria
- A new Skill file at
.github/skills/ambient-properties/SKILL.md
- The Skill is self-contained and can be used by Copilot agents to implement new ambient properties
- The Skill references concrete code examples from the WinForms codebase
- Any
DataContext retrofit items are tracked as separate issues
Background
WinForms has a concept of ambient properties properties that cascade from a parent control to all its children unless a child explicitly overrides the value. The canonical example is
DataContext(introduced in .NET 7 via PR #7143), but the pattern also applies to properties likeFont,BackColor,ForeColor,Cursor, andBindingContext.When adding new APIs to WinForms controls, contributors sometimes need to implement ambient properties. The current
new-control-apiSkill covers standard property patterns but explicitly defers ambient properties to a separate, dedicated Skill.Motivation
DataContextimplementation may not fully follow the canonical ambient property approach. A Skill would codify the correct pattern for future APIs.CreateParams) are called from the base class constructor before the derived class constructor body runs. Ambient properties must handle this safely the Skill should document the pitfalls.PropertyStore.TryGetValuewith a parent-fallback chain. The Skill should prescribe the exact getter/setter pattern, including when to store vs. remove values.OnParent[Property]Changedmethod must propagate changes to children. The Skill should define the canonical implementation, including disposal guards and child iteration.DataContextimplementation should be reviewed against the codified Skill pattern to identify any gaps that should be addressed in .NET 11.Core Issues to Address in the Skill
PropertyStore.TryGetValuewithParentInternal?.PropertyfallbackShouldSerialize/Resetmethods that usePropertyStore.ContainsKeyOn[Property]Changedmust guard against disposal, invoke event handler, then iterate children callingOnParent[Property]ChangedOnParent[Property]Changedmust check whether child has an explicit value before propagatingDataContextimplementation for conformance and identify .NET 11 retrofit itemsAcceptance Criteria
.github/skills/ambient-properties/SKILL.mdDataContextretrofit items are tracked as separate issues