Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Microsoft.Maui.Controls;
using System;
using System.Threading.Tasks;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Hosting;
using System;
using System.Threading.Tasks;
using Xunit;
using Microsoft.Maui.Platform;
using Xunit;

namespace Microsoft.Maui.DeviceTests;

Expand Down Expand Up @@ -98,4 +98,58 @@ string GetDisplayedText(DatePickerHandler handler)

return string.Empty;
}

[Fact(DisplayName = "DateSelected Event Fires When Platform View Date Changes")]
public async Task DateSelectedEventFiresWhenPlatformViewDateChanges()
{
SetupBuilder();

var originalDate = new DateTime(2023, 5, 15);
var newDate = new DateTime(2023, 8, 20);

var datePicker = new DatePicker
{
Date = originalDate
};

bool eventFired = false;

datePicker.DateSelected += (sender, e) =>
{
eventFired = true;
};

await CreateHandlerAndAddToWindow<DatePickerHandler>(datePicker, async (handler) =>
{
await InvokeOnMainThreadAsync(() =>
{
#if ANDROID
if (handler.DatePickerDialog != null)
{
var previousDate = handler.VirtualView.Date;
handler.VirtualView.Date = newDate;
}
#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.
typeof(DatePickerHandler).GetMethod("SetVirtualViewDate",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)?
.Invoke(handler, null);
}
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.
#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.
}
Comment on lines +141 to +144
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.
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.
#else
handler.VirtualView.Date = newDate;
#endif
});

await Task.Delay(20);

Assert.True(eventFired, "DateSelected event should fire when platform view date changes");
});
}
}
4 changes: 2 additions & 2 deletions src/Core/src/Handlers/DatePicker/DatePickerHandler.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ internal static partial void MapIsOpen(IDatePickerHandler handler, IDatePicker d
handler.PlatformView?.UpdateIsOpen(datePicker);
}

private void DateChanged(CalendarDatePicker sender, CalendarDatePickerDateChangedEventArgs args)
void DateChanged(CalendarDatePicker sender, CalendarDatePickerDateChangedEventArgs args)
{
if (VirtualView is null)
{
Expand All @@ -75,7 +75,7 @@ private void DateChanged(CalendarDatePicker sender, CalendarDatePickerDateChange
return;
}

if (VirtualView.Date is null)
if (VirtualView.Date != args.NewDate.Value.DateTime)
{
VirtualView.Date = args.NewDate.Value.DateTime;
}
Expand Down
Loading