Having Trouble Setting Window's Owner in Parent's Constructor

后端 未结 4 1349
慢半拍i
慢半拍i 2021-02-12 14:25

Is there anything wrong in WPF with setting the Owner property of a window to its parent in that parent\'s constructor? There shouldn\'t be, right? So why am I getting an

4条回答
  •  不思量自难忘°
    2021-02-12 15:06

    I ended up subscribing to Window.Activated, not Window.StateChanged. Be sure to unsubscribe to it in the handler, as advised in the comments.

        private void OnActivated(object sender, EventArgs eventArgs)
        {
            owned.Owner = this;
            Activated -= OnActivated;
        }
    

    I accepted dlev's answer because it led me directly to finding the answer, even if his didn't work for my exact situation.

提交回复
热议问题