* test: add failing test for Loaded processing after handler exception
A control whose Loaded handler throws currently breaks the static
loaded-processing machinery: remaining controls in the same dispatcher
batch are skipped and, because _isLoadedProcessing is never reset,
every control created afterwards app-wide never receives Loaded.
The test attaches a throwing control between two siblings, expects the
exception to surface from the dispatcher job, and asserts that both
siblings and a control added in a later batch still get Loaded.
Issue #18742
* fix: recover Loaded event processing after a handler throws
Previously the static loadedProcessingAction iterated the pending
controls with no exception handling. If any control's Loaded handler
or OnLoaded override threw, the batch loop aborted, so:
- _isLoadedProcessing stayed true forever, and since
ScheduleOnLoadedCore only posts a dispatcher job when that flag is
false, no control created afterwards, app-wide, ever received
Loaded;
- the remaining controls in the current batch were skipped;
- the stuck processing queue retained control references (leak).
The invariant violated was that _isLoadedProcessing is true only while
a loaded-processing dispatcher job is actually scheduled or running.
Fix: process the snapshot as a drain queue (Dequeue before invoking,
because OnLoadedCore must not run twice for a control) and restore the
invariant in a finally block: requeue the unprocessed remainder, clear
the processing queue, reset the flag and post a new dispatcher job if
work remains. try/finally was chosen over catching per control so the
exception still propagates to the dispatcher as an unhandled exception
(matching WPF semantics) instead of being swallowed or aggregated,
while controls after the faulty one get Loaded on the next dispatcher
job.
Fixes#18742