Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,8 @@ protected override void OnGotFocus(EventArgs e)
{
base.OnGotFocus(e);

NotifyWinEvent(AccessibleEvents.Focus);

if (IsAccessibilityObjectCreated)
{
((MonthCalendarAccessibleObject)AccessibilityObject).FocusedCell?.RaiseAutomationEvent(UIA_EVENT_ID.UIA_AutomationFocusChangedEventId);
Expand Down Expand Up @@ -2063,8 +2065,9 @@ private unsafe void WmDateChanged(ref Message m)
_selectionStart = start;
_selectionEnd = end;

AccessibilityNotifyClients(AccessibleEvents.NameChange, -1);
AccessibilityNotifyClients(AccessibleEvents.ValueChange, -1);
NotifyWinEvent(AccessibleEvents.Focus);
NotifyWinEvent(AccessibleEvents.NameChange);
NotifyWinEvent(AccessibleEvents.ValueChange);

// We should use the Date for comparison in this case. The user can work in the calendar only with dates,
// while the minimum / maximum date can contain the date and custom time, which, when comparing Ticks,
Expand Down Expand Up @@ -2094,6 +2097,25 @@ private unsafe void WmDateChanged(ref Message m)
OnDateChanged(new DateRangeEventArgs(start, end));
}

private void NotifyWinEvent(AccessibleEvents accessibleEvent)
{
try
{
if (IsHandleCreated)
{
PInvoke.NotifyWinEvent(
(uint)accessibleEvent,
this,
(int)OBJECT_IDENTIFIER.OBJID_CLIENT,
(int)PInvoke.CHILDID_SELF);
}
}
catch (Exception ex) when (!ex.IsCriticalException())
{
Debug.Fail($"NotifyWinEvent failed: {ex.Message}");
}
}

/// <summary>
/// Handles the MCN_GETDAYSTATE notification by returning an array of bitmasks, one entry per month,
/// that specifies which dates to display in bold.
Expand Down