C# windowStyle=None 的不可调整大小的窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1570106/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 18:58:00  来源:igfitidea点击:

Non-resizable windows with windowStyle=None

c#.netwpfwindow

提问by Daniel

Basically, I want to create a window that looks like the following: alt text http://www.thex9.net/screenshots/2009-10-15_1347.png

基本上,我想创建一个如下所示的窗口: alt text http://www.thex9.net/screenshots/2009-10-15_1347.png

However, the window shouldn't be resizable (the one in the screenshot is) but must retain the glass border. The XAML for the window in the screenshot is as follows:

但是,窗口不应调整大小(屏幕截图中的那个),但必须保留玻璃边框。屏幕截图中窗口的 XAML 如下:

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="WpfApplication1.MainWindow"
    x:Name="Window" Title="MainWindow" WindowStyle="None">    
 <Grid x:Name="LayoutRoot"/>
</Window>

Is it possible to create a window which looks similar to the one in my screenshot but is not resizable? Any help would be very much appreciated.

是否可以创建一个与我的屏幕截图中的窗口相似但不可调整大小的窗口?任何帮助将不胜感激。

回答by Drew Marsh

One way to accomplish a fixed size Window while retaining the border is to set the Min[Width|Height] and Max[Width|Height] properties to be the same value. The border will still show the resize cursor, but the user will not be able to change the size of the Window.

在保留边框的同时实现固定大小窗口的一种方法是将 Min[Width|Height] 和 Max[Width|Height] 属性设置为相同的值。边框仍会显示调整大小的光标,但用户将无法更改窗口的大小。

If the fact that the border still indicates that it's resizable bothers you, the next step is to set the ResizeMode="NoResize", but then you have to start drawing your own Aero glass if you want to retain the glass edges.

如果边框仍然表明它可以调整大小这一事实让您感到困扰,下一步是设置 ResizeMode="NoResize",但是如果您想保留玻璃边缘,则必须开始绘制自己的 Aero 玻璃。

回答by Wojciech Papaj

Probably you can get desired result by: ResizeMode=
XAML object property which can take have following states:

可能您可以通过以下方式获得所需的结果: ResizeMode=
XAML 对象属性,它可以具有以下状态:

  • NoResize - A window cannot be resized. The Minimize and Maximize buttons are not displayed in the title bar.
  • CanMinimize - A window can only be minimized and restored. The Minimize and Maximize buttons are both shown, but only the Minimize button is enabled.
  • CanResize - A window can be resized. The Minimize and Maximize buttons are both shown and enabled.
  • CanResizeWithGrip - A window can be resized. The Minimize and Maximize buttons are both shown and enabled. A resize grip appears in the bottom-right corner of the window.
  • NoResize - 无法调整窗口大小。标题栏中不显示最小化和最大化按钮。
  • CanMinimize - 窗口只能最小化和恢复。最小化和最大化按钮均显示,但仅启用了最小化按钮。
  • CanResize - 可以调整窗口大小。最小化和最大化按钮均显示并启用。
  • CanResizeWithGrip - 可以调整窗口大小。最小化和最大化按钮均显示并启用。窗口右下角会出现一个调整大小的夹点。