Fix occasional crash opening settings dialog

(caused by visual tree sometimes not having completely loaded. Since the
original code came from SO, I've also described the fix here:
http://stackoverflow.com/a/27447702/208817)