Properly detaching visual tree when template is changed.