windowState and SizeToContent do not work simultaneously

前端 未结 1 1807
既然无缘
既然无缘 2021-01-27 07:34

I am trying to have the SizeToContent=\"WidthAndHeight\" and WindowState = \"Maximized\" at the same time. I tried to change the state of my window during loading, as well as in

1条回答
  •  南方客
    南方客 (楼主)
    2021-01-27 08:12

    Thanks Eugene, I got the idea. I already tried to change the state of my MainWindow at run time, but it didn't work out (MainWindow didn't occupy the full screen).

    The reason, as Eugene mentioned, is that these properties conflict with each other (SizeToContent gets the priority) so I have to turn one off in order to be able to turn the other on. Hence, to solve the problem:

    private void MainWindowMy_Loaded(object sender, RoutedEventArgs e)
    {
        this.SizeToContent = System.Windows.SizeToContent.Manual;
        this.WindowState = System.Windows.WindowState.Maximized;
    }
    

    It's not the most elegant way of doing it, but it serves the purpose for now. However, if anybody could come up with a more elegant solution, it would be greatly appreciated.

    0 讨论(0)
提交回复
热议问题