Skip to content

Conversation

@TomEdwardsEnscape
Copy link
Contributor

@TomEdwardsEnscape TomEdwardsEnscape commented Jul 12, 2025

Some mis-use of nullability checking was noted in #19210, but the problem goes much deeper. This PR moves template part fields into a struct, which is used by a nullable field on the presenter. This two-layer approach allows us to differentiate between optional and required template parts at compile time, while still allowing the template to be applied after the constructor has executed.

The only remaining uses of the ! character in the two affected files are boolean inversion operations.

What is the updated/expected behavior with this PR?

There are no changes to behaviour, but:

  • Fixed obscure cases where NullReferenceException could be thrown if a template hasn't been applied yet, or where it provides only some optional items.
  • Replaced repeated string literals with nameof.
  • Relaxed template part requirements: RepeatButton to Button, Rectancle to Control.

Breaking changes

None

Obsoletions / Deprecations

None

Fixed issues

Addresses one of the complaints made in #19210.

@maxkatz6
Copy link
Member

Can you revert back to blocked namespaces? This change is something we want, but it needs to be done at least in a separated commit that can be added to .git-blame-ignore-revs.

@maxkatz6
Copy link
Member

There is a need to rewrite styling of these two controls. See #17515

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0057692-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@TomEdwardsEnscape TomEdwardsEnscape force-pushed the fixes/datetimepicker-nullability branch from db1f45d to 59525cc Compare July 12, 2025 14:18
@TomEdwardsEnscape
Copy link
Contributor Author

TomEdwardsEnscape commented Jul 12, 2025

I removed the namespace change, but do you know that you can do git blame -w to automatically ignore this sort of thing?

There is a need to rewrite styling of these two controls. See #17515

I've struggled with these controls for this exact reason. Any improvements ought not to break existing themes, so these changes are still worthwhile.

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0057694-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@robloo
Copy link
Contributor

robloo commented Jul 19, 2025

You are doing something new here: creating a struct for the template parts. Naming the controls exactly the same as the XAML template part name and then using nameof() has been done before -- it's the struct that's new.

I think this should be considered as part of the overall discussions below. All ideas essentially converged to code generators to solve this problem.

Copy link
Member

@MrJul MrJul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! As mentioned by Max, this control really needs a rewrite, there are really too many template parts. This doesn't prevent fixing the nullability issues in the meantime :)

@MrJul MrJul added bug backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch labels Jul 30, 2025
…ckerPresenter

Fixed obscure cases where NullReferenceException could be thrown if a template hasn't been applied yet, or where it provides only some optional items
Replaced repeated string literals with shared const values
Relaxed template part requirements: RepeatButton to Button, Rectancle to Control
@TomEdwardsEnscape TomEdwardsEnscape force-pushed the fixes/datetimepicker-nullability branch from 59525cc to 2a86a4c Compare August 7, 2025 18:48
@TomEdwardsEnscape TomEdwardsEnscape requested a review from MrJul August 7, 2025 18:48
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0058106-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Copy link
Member

@MrJul MrJul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@MrJul MrJul enabled auto-merge August 8, 2025 08:07
@MrJul MrJul added this pull request to the merge queue Aug 8, 2025
Merged via the queue into AvaloniaUI:master with commit 995f8ed Aug 8, 2025
11 checks passed
MrJul pushed a commit that referenced this pull request Aug 15, 2025
…ckerPresenter (#19241)

Fixed obscure cases where NullReferenceException could be thrown if a template hasn't been applied yet, or where it provides only some optional items
Replaced repeated string literals with shared const values
Relaxed template part requirements: RepeatButton to Button, Rectancle to Control
@MrJul MrJul added backported-11.3.x and removed backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch labels Aug 15, 2025
@TomEdwardsEnscape TomEdwardsEnscape deleted the fixes/datetimepicker-nullability branch September 5, 2025 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants