Fix issue 15067: Control.Visible binding does not activate when Visible was explicitly set to false before DataBindings.Add was called - #15096
Open
SimonZhao888 wants to merge 2 commits into
Conversation
…le was explicitly set to false before DataBindings.Add was called
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15096 +/- ##
=============================================
Coverage 37.24166% 37.24166%
=============================================
Files 246 246
Lines 9774 9774
Branches 1029 1029
=============================================
Hits 3640 3640
Misses 5970 5970
Partials 164 164
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
One or more issues must be addressed before approval.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Fixes pre-handle Control.Visible binding activation while preserving initially hidden controls.
Changes:
- Enables early Visible binding checks and activation.
- Delays the initial data push for explicitly hidden controls.
- Adds a regression test for source-driven visibility updates.
File summaries
| File | Description |
|---|---|
| src/test/unit/System.Windows.Forms/System/Windows/Forms/ControlBindingsCollectionTests.cs | Updated as part of this pull request. |
| src/System.Windows.Forms/System/Windows/Forms/DataBinding/Binding.cs | Updated as part of this pull request. |
| src/System.Windows.Forms/System/Windows/Forms/DataBinding/Binding.BindToObject.cs | Updated as part of this pull request. |
Review details
Suppressed comments (2)
src/System.Windows.Forms/System/Windows/Forms/DataBinding/Binding.cs:235
- This new path can create a manager for a pre-created control at design time, even though
BindToObject.CheckBindingdeliberately returns early whenControlAtDesignTime()is true. That leavesFieldInfounset;UpdateIsBindingcan then activate the binding andPushData()may try to format the entire data source asVisible(or wire runtime notifications) in the designer. Keep the pre-creation exception disabled for design-time components, or otherwise defer activation until the design-time binding check can initialize the field.
BindableComponent is not null && (IsComponentCreated(BindableComponent) || SupportsBindingBeforeComponentCreated(BindableComponent))
? BindableComponent.BindingContext
: null,
src/System.Windows.Forms/System/Windows/Forms/DataBinding/Binding.cs:1171
- When
ControlUpdateModeisNever, the existing activation path deliberately callsPullData(..., force: true)because this mode is write-only with respect to the data source. Putting that call behind!shouldDelayInitialDataPushmeans a hidden control's initial value is neither written to the source nor updated later (PushData()returns immediately forNever), so this changes the documented behavior for this mode. Keep the preservation guard around only the data-source-to-controlPushData()branch and still execute thePullDatabranch.
if (IsBinding && !shouldDelayInitialDataPush)
{
if (_controlUpdateMode == ControlUpdateMode.Never)
{
PullData(reformat: false, force: true);
}
else
{
PushData();
}
- Files reviewed: 3/3 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #15067
Root Cause
Control.Visible binding activation was gated by component creation (ComponentCreated / handle-created path).
When Visible was explicitly set to false before DataBindings.Add, the control could remain in a pre-created state where the binding did not fully activate, so later INotifyPropertyChanged updates were not applied as expected.
Additionally, once enabling early activation for Visible, an immediate initial push from data source could overwrite an explicitly set local Visible value. That required preserving the user/designer-set value on first bind.
Proposed changes
Customer Impact
Regression?
Risk
Screenshots
Before
Recording.2026-09-15.115046.mp4
After
Recording.2026-09-15.115721.mp4
Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow