Panel: Allow dynamically created close buttons

This change allows dynamically created close buttons to close the panel.

Fixes Issue #5927 - Panel: Dynamically created close elements do not close the panel