KEMBAR78
Fixed DatePicker's DateSelected event not firing on Windows - NET 10 Preview 6 by Dhivya-SF4094 · Pull Request #30748 · dotnet/maui · GitHub
Skip to content

Conversation

@Dhivya-SF4094
Copy link
Contributor

@Dhivya-SF4094 Dhivya-SF4094 commented Jul 22, 2025

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Issue detail:

DatePicker's DateSelected event not firing on Windows - .NET 10 Preview 6

Root Cause

The DateSelected event was not firing on Windows due to an incorrect condition check. The original code used if (VirtualView.Date is null), which did not properly capture changes to the selected date. Although Date can be set to null, the check was not sufficient to determine whether the date had actually changed. As a result, the selected date was not updated, and the event was not triggered.

Description of Change

To resolve these issues, the condition was updated to if (VirtualView.Date != args.NewDate.Value.DateTime) to ensure the event triggers only when the selected date actually changes.

Validated the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Issues Fixed:

Fixes #30736

Screenshots

Before After
30736_BeforeFix.mp4
30736_AfterFix.mp4

@dotnet-policy-service dotnet-policy-service bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels Jul 22, 2025
@jsuarezruiz jsuarezruiz added the area-controls-datetimepicker DatePicker, TimePicker label Jul 22, 2025
@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@Dhivya-SF4094 Dhivya-SF4094 marked this pull request as ready for review July 23, 2025 07:50
@Copilot Copilot AI review requested due to automatic review settings July 23, 2025 07:50
@Dhivya-SF4094 Dhivya-SF4094 requested a review from a team as a code owner July 23, 2025 07:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug where the DatePicker's DateSelected event was not firing on Windows in .NET 10 Preview 6. The issue was caused by an incorrect null check condition that prevented the event from being triggered when the date changed.

  • Fixed the conditional logic in DatePickerHandler.Windows.cs to properly detect date changes
  • Added comprehensive device tests to verify the DateSelected event fires across all platforms
  • Removed unnecessary access modifier from the DateChanged method

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
src/Core/src/Handlers/DatePicker/DatePickerHandler.Windows.cs Fixed condition check from null comparison to actual date comparison and cleaned up method signature
src/Controls/tests/DeviceTests/Elements/DatePicker/DatePickerTests.cs Added comprehensive test coverage for DateSelected event firing across all platforms

Comment on lines 54 to 138
if (handler.DatePickerDialog != null)
{
handler.DatePickerDialog.SetDate(newDate.ToNSDate(), false);
}
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

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

Inconsistent indentation detected. This line uses spaces while the surrounding code uses tabs. Please maintain consistent indentation throughout the file.

Suggested change
if (handler.DatePickerDialog != null)
{
handler.DatePickerDialog.SetDate(newDate.ToNSDate(), false);
}
if (handler.DatePickerDialog != null)
{
handler.DatePickerDialog.SetDate(newDate.ToNSDate(), false);
}

Copilot uses AI. Check for mistakes.

#elif IOS
if (handler.DatePickerDialog != null)
{
handler.DatePickerDialog.SetDate(newDate.ToNSDate(), false);
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

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

Inconsistent indentation detected. This line uses spaces while the surrounding code uses tabs. Please maintain consistent indentation throughout the file.

Suggested change
handler.DatePickerDialog.SetDate(newDate.ToNSDate(), false);
handler.DatePickerDialog.SetDate(newDate.ToNSDate(), false);

Copilot uses AI. Check for mistakes.

if (handler.DatePickerDialog != null)
{
handler.DatePickerDialog.SetDate(newDate.ToNSDate(), false);
}
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

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

Inconsistent indentation detected. This line uses spaces while the surrounding code uses tabs. Please maintain consistent indentation throughout the file.

Suggested change
}
}

Copilot uses AI. Check for mistakes.

Comment on lines +59 to +143
if (handler.PlatformView != null)
{
handler.PlatformView.Date = newDate;
}
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

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

Inconsistent indentation detected. This line uses spaces while the surrounding code uses tabs. Please maintain consistent indentation throughout the file.

Suggested change
if (handler.PlatformView != null)
{
handler.PlatformView.Date = newDate;
}
if (handler.PlatformView != null)
{
handler.PlatformView.Date = newDate;
}

Copilot uses AI. Check for mistakes.

#elif WINDOWS
if (handler.PlatformView != null)
{
handler.PlatformView.Date = newDate;
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

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

Inconsistent indentation detected. This line uses spaces while the surrounding code uses tabs. Please maintain consistent indentation throughout the file.

Suggested change
handler.PlatformView.Date = newDate;
handler.PlatformView.Date = newDate;

Copilot uses AI. Check for mistakes.

if (handler.PlatformView != null)
{
handler.PlatformView.Date = newDate;
}
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

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

Inconsistent indentation detected. This line uses spaces while the surrounding code uses tabs. Please maintain consistent indentation throughout the file.

Suggested change
}
}

Copilot uses AI. Check for mistakes.

handler.PlatformView.Date = newDate;
}
#elif MACCATALYST
handler.PlatformView.Date = newDate.ToNSDate();
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

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

Inconsistent indentation detected. This line has an extra space before the tab character. Please maintain consistent indentation throughout the file.

Suggested change
handler.PlatformView.Date = newDate.ToNSDate();
handler.PlatformView.Date = newDate.ToNSDate();

Copilot uses AI. Check for mistakes.

@jfversluis jfversluis added this to the .NET 10 SR1 milestone Aug 7, 2025
@jfversluis
Copy link
Member

jfversluis commented Aug 7, 2025

The original code used if (VirtualView.Date is null), which was always false since Date is a non-nullable DateTime

This is not entirely true. A change we made in .NET 10 is to make the Date property nullable. Can you please double check (and add a test) to make sure it works with both a different value and null?

Also please resolve the conflicts and address the feedback.

Copy link
Member

@jfversluis jfversluis left a comment

Choose a reason for hiding this comment

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

See above

@Dhivya-SF4094
Copy link
Contributor Author

The original code used if (VirtualView.Date is null), which was always false since Date is a non-nullable DateTime

This is not entirely true. A change we made in .NET 10 is to make the Date property nullable. Can you please double check (and add a test) to make sure it works with both a different value and null?

Also please resolve the conflicts and address the feedback.

@jfversluis I have updated the PR description to reflect that the Date property is nullable in .NET 10. I also verified that the fix correctly checks whether the new date differs from the existing one before firing the DateSelected event.

attempted to add a test case that sets the Date to null, but it currently throws an exception. This issue will be handled in a separate PR, and a subsequent test case would be added in the same PR.

@jfversluis
Copy link
Member

@Dhivya-SF4094 Can you resolve the conflict please? :)

@Dhivya-SF4094
Copy link
Contributor Author

@Dhivya-SF4094 Can you resolve the conflict please? :)

Conflicts has been resolved.

@jfversluis jfversluis modified the milestones: .NET 10 SR1, .NET 10.0-rc1 Aug 18, 2025
@jfversluis
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Copy link
Member

@jfversluis jfversluis left a comment

Choose a reason for hiding this comment

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

See above

@jfversluis jfversluis merged commit b104fe1 into dotnet:net10.0 Aug 18, 2025
129 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Sep 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-datetimepicker DatePicker, TimePicker community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants