Skip to content

Handle non-convertible data trigger values safely - #366

Merged
wieslawsoltes merged 4 commits into
masterfrom
agent/346-data-trigger-conversion
Aug 19, 2026
Merged

wieslawsoltes merged 4 commits into
masterfrom
agent/346-data-trigger-conversion

Conversation

@wieslawsoltes

Copy link
Copy Markdown
Owner

Summary

Prevents DataTriggerBehavior and shared comparison conditions from throwing when a string Value cannot be converted to the runtime type of Binding.

Contract

A conversion or compatible-comparison failure now uses non-equal semantics:

  • NotEqual evaluates to true.
  • Equal and all relational operators evaluate to false.

This lets dynamically generated or design-time-incomplete triggers remain inert until their values become compatible.

Root cause

The initial string conversion called TypeConverterHelper.Convert without guarding its standard conversion failures. Primitive parsing such as int.Parse could therefore propagate FormatException or OverflowException.

The later comparable path handled only part of the conversion surface and called IComparable.CompareTo without guarding incompatible-operand exceptions.

Changes

  • Guard string conversion failures for format, invalid cast, unsupported conversion, and overflow.
  • Guard the same standard failures from Convert.ChangeType.
  • Treat ArgumentException or InvalidCastException from CompareTo as incompatible operands.
  • Centralize the non-equal result rule.
  • Add direct tests covering:
    • all six comparison operators with a non-convertible integer string;
    • numeric overflow;
    • an IComparable implementation that rejects the other operand.
  • Add an end-to-end DataTriggerBehavior test proving dispatcher evaluation neither throws nor executes actions.
  • Document the compatibility semantics.

Unexpected exceptions outside these known conversion/comparison incompatibilities continue to propagate.

Validation

  • Focused comparison tests: 9 passed
  • Focused DataTriggerBehavior regression: 1 passed
  • Xaml.Behaviors.Interactivity.UnitTests: 102 passed
  • Xaml.Behaviors.Interactions.UnitTests: 90 passed, 2 existing skipped
  • git diff --check: clean

Closes #346

@wieslawsoltes
wieslawsoltes marked this pull request as ready for review July 14, 2026 22:18
@wieslawsoltes
wieslawsoltes merged commit f04cf37 into master Aug 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DataTrigger comparison throws on non-convertible string Value

1 participant