-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
needs-area-labeluntriagedThe team needs to look at this issue in the next triageThe team needs to look at this issue in the next triage
Description
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
DataContextimplementation 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.TryGetValuewith 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]Changedmethod must propagate changes to children. The Skill should define the canonical implementation, including disposal guards and child iteration. - DataContext retrofit. The existing
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
- Define the canonical getter pattern:
PropertyStore.TryGetValuewithParentInternal?.Propertyfallback - Define the canonical setter pattern: store only when different from parent, remove when equal to parent (to re-enable inheritance)
- Define
ShouldSerialize/Resetmethods that usePropertyStore.ContainsKey - Define
On[Property]Changedmust guard against disposal, invoke event handler, then iterate children callingOnParent[Property]Changed - Define
OnParent[Property]Changedmust check whether child has an explicit value before propagating - Document the constructor ordering hazard and how PropertyStore avoids it
- Document which existing WinForms properties are ambient (Font, BackColor, ForeColor, Cursor, BindingContext, DataContext) as reference implementations
- Review
DataContextimplementation for conformance and identify .NET 11 retrofit items
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
DataContextretrofit items are tracked as separate issues
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
needs-area-labeluntriagedThe team needs to look at this issue in the next triageThe team needs to look at this issue in the next triage