[Bug] DataTrigger not applied when null at initial
- Dominant language
- C#
- Stars
- 23.3k
- Forks
- 2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 290
Description
### Description
The `DataTrigger` is not applied if the value is `null` at the beginning, but it is applied later if the value changes.
Binding to:
- **Nullable** type with default value => Trigger **not applied** at beginning
- **Non nullable** type with default value => Trigger **applied** at beginning
So the trigger is applied at the beginning only if the Binding value is not null. I think the behavior is not consistent, the trigger should be applied at the beginning as well, even if the value is null.
Reproduction project available here: https://github.com/MADSENSE/MADSENSE.MAUI.Sample.App/tree/datatrigger-initial-null
Already tracked by https://github.com/xamarin/Xamarin.Forms/issues/13544
### Steps to Reproduce
1. Define DataTrigger with Binding to nullable type
2. The DataTrigger is not applied at beginning, only on value change back to null
### Expected Behavior
`DataTrigger` applied at beginning, even if null binding value.
### Actual Behavior
`DataTrigger` with null binding value not applied at beginning.
BTW it seems that the DataTrigger keeps the last value (eg: on Value=2, the `BackgroundColor` should revert back to transparent)

### Version with bug
Release Candidate 2 (current)
### Last version that worked well
Unknown/Other
### Affected platforms
iOS, Android, Windows
### Affected platform versions
Windows 10.0.19041
### Did you find any workaround?
Define `Binding.TargetNullValue` or `Binding.Converter`
### Relevant log output
_No response_
Contributor guide
Research direction
Start with the linked MADSENSE.MAUI.Sample.App reproduction on its datatrigger-initial-null branch and run the nullable-binding case on an affected platform. Compare the initial null state with a later change back to null; done means the DataTrigger applies at startup and the property reverts correctly when the binding is null.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- frontend, mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100