[BUG #8341] - Wrong behavior while switching themes
(cherry picked from commit d995f703e62fa7552733ef1bbb178b9cee2ebf57)