fix the OwningWindow is null

set the OwningWindow value before using it
Merge pull request #1257 from ye4241/master

fix the OwningWindow is null