Detach and attach when adding or removing the caption wrapper (#11708)

Change-Id: Ie6de4863587189ef1105cc41211b224c126f6ebd