WPF WindowStartupLocation=“CenterOwner” not really center, and pops all over, why?

后端 未结 5 613
陌清茗
陌清茗 2020-12-29 00:54

Well this question and this question are similar but no answers that work. In fact I was hoping WindowStartupLocation=CenterOwner would work...it doesn\'t. It seems to cent

5条回答
  •  情深已故
    2020-12-29 01:34

    In addition, we can use:

    this.Owner = App.Current.MainWindow;
    

    Or Application instead of App.
    And place it in a child window constructor:

        public partial class ChildWindow : Window
        {
            public ChildWindow()
            {
                InitializeComponent();
    
                DataContext = new ChildWindowViewModel();
    
                this.Owner = App.Current.MainWindow;
            }
        }
    

提交回复
热议问题