Skip to content

Fix trigger value lost when local override is cleared while trigger remains active#240

Merged
tedd merged 1 commit into
forge/dependency-property-precedence-13154332135025318484from
copilot/sub-pr-232-again
Mar 25, 2026
Merged

Fix trigger value lost when local override is cleared while trigger remains active#240
tedd merged 1 commit into
forge/dependency-property-precedence-13154332135025318484from
copilot/sub-pr-232-again

Conversation

Copilot AI commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

EvaluateTriggers() only fires when a condition property changes, so the re-apply path (wasActive && !HasLocalValue → shouldApplySetter = true) in Control.cs was never reached when a setter property was cleared — leaving the trigger value un-applied until the condition toggled.

Changes

DependencyObject — layered value store

  • Added _localOverridesActiveTrigger: HashSet<DependencyProperty> to track when SetValue is called while a trigger is active
  • Trigger value is now kept in _triggerValues when a local override is set (previously removed)
  • GetValue precedence: PostTriggerLocal (_localOverridesActiveTrigger + _localValues) → Trigger (_triggerValues) → PreTriggerLocal → Inherited → Default
  • ClearValue removes the override flag; the trigger value surfaces automatically on the next GetValue — no EvaluateTriggers() call needed
  • ClearTriggerValue cleans up the override flag when the trigger deactivates

Control — remove flawed re-apply path

  • Removed the wasActive && !target.HasLocalValue(...) re-apply block; the precedence model makes it unnecessary

Tests

  • Added Trigger_ReExposesTriggerValue_AfterClearValueWhileActive regression test covering the full activate → SetValue → ClearValue → deactivate cycle
control.IsHovered = true;   // trigger active → TestValue == 42
control.TestValue = 999;    // local override
control.ClearValue(TestControl.TestValueProperty);
Assert.Equal(42, control.TestValue); // trigger value re-exposed without EvaluateTriggers()

control.IsHovered = false;
Assert.Equal(0, control.TestValue); // reverts to default on deactivate

💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Copilot AI changed the title [WIP] [WIP] Address feedback on DependencyProperty/Trigger parity integration Fix trigger value lost when local override is cleared while trigger remains active Mar 25, 2026
Copilot AI requested a review from tedd March 25, 2026 17:51
Copilot finished work on behalf of tedd March 25, 2026 17:51
@tedd
tedd marked this pull request as ready for review March 25, 2026 17:52
Copilot AI review requested due to automatic review settings March 25, 2026 17:52
@tedd
tedd merged commit 3694600 into forge/dependency-property-precedence-13154332135025318484 Mar 25, 2026
2 checks passed

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.

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

3 participants