0
votes

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 the Constructor of the MainWindow, but no luck.

<Window x:Name="MainWindowMy" x:Class="ManyTabControls.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    Title="Pressure Vessel Design"  WindowState="Maximized" SizeToContent="WidthAndHeight" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Auto" Loaded="MainWindowMy_Loaded"  >
<Window.Resources>

I have got a TabControl with a lot of tabs, in the design viewer, tabs are flowing down into different rows. And when I change the width of the TabControl so that the tabs be in the same line, then they go outside the boundary of the MainWindow. And if I set the width of the Mainwindow, then the MainWindow would have a constant width. That means if the size of monitor gets smaller, then part of the MainWindow that is bigger than the screen will not be displayed. I hope I made myself clear.

1
How do you expect Maximised and SizeToContent to work together? They are contradictory. What do you expect to happen?dkozl
And what does happen? "no luck" is not a good problem statement.Henk Holterman
When the window is loaded, it doesn't get maximized. Why it cannot have the size of the content and get maximized when loaded. As you can see both the attributes are coexisting! How can one gets priority to the other one.BhupinderTube
Maximised means that the window regardless of its contents must fill entire screen space, SizeToContent means that regardless of its size it must shrink or increase its size to fit the contents. They are completely incompatible, because they act differently under the same circumstances, but due to the order of layout calculations SizeToContent has greater priority (or some sort of). And how should they work both at the same time? For example, your have 1 control 100x100 pixels and your screen is 1000*500, how should the layout look like?Eugene Podskal
What I am trying to achieve is that when I am in the design viewer, I would like to be able to view all the contents of tabControls, grids,etc and once I start my application, the window would fill the whole screen. I have got 2 options, one to set a width and height to my window, but then it can get out of the screen if screen gets smaller. And another option is to use Size to Content, in the design viewer, and as soon as application starts, it would ignore it and apply WindowState="Maximised". Or I would like to apply Windowstate="Maximised" only,BhupinderTube

1 Answers

1
votes

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.