windowState 和 SizeToContent 不能同时工作 [英] windowState and SizeToContent do not work simultaneously

查看:26
本文介绍了windowState 和 SizeToContent 不能同时工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试同时使用 SizeToContent="WidthAndHeight" 和 WindowState = "Maximized".我试图在加载过程中以及在 MainWindow 的构造函数中更改窗口的状态,但没有成功.

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>

我有一个带有很多选项卡的 TabControl,在设计查看器中,选项卡向下流动到不同的行.当我更改 TabControl 的宽度以使选项卡在同一行中时,它们就会超出 MainWindow 的边界.如果我设置 Mainwindow 的宽度,那么 MainWindow 将具有恒定的宽度.这意味着如果显示器的尺寸变小,那么比屏幕大的 MainWindow 部分将不会显示.我希望我说清楚了.

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.

推荐答案

谢谢 Eugene,我明白了.我已经尝试在运行时更改 MainWindow 的状态,但没有成功(MainWindow 没有占据全屏).

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).

原因,正如 Eugene 所提到的,是这些属性相互冲突(SizeToContent 获得优先权),所以我必须关闭一个才能打开另一个.因此,要解决问题:

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.

这篇关于windowState 和 SizeToContent 不能同时工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆