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

后端 未结 5 611
陌清茗
陌清茗 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:25

    Something else that can cause this is setting DataContext after InitializeComponent() is called.

    If you have code-behind like this:

        public CustomWindow(CustomViewModel viewModel)
        {
            InitializeComponent();
            DataContext = viewModel;
        }
    

    Change it to:

        public CustomWindow(CustomViewModel viewModel)
        {
            DataContext = viewModel;
            InitializeComponent();
        }
    

提交回复
热议问题