简体   繁体   English

如何设置窗口的调整大小限制?

[英]How to set a resize limit for a window?

Lets say I have a xaml for my window like this: 让我说我的窗口有一个像这样的xaml:

<Window x:Class="WavePoint_MVVM.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    FontSize="13" 
    FontFamily="Verdana"
    xmlns:local="clr-namespace:WavePoint_MVVM"
    Height="{Binding SystemParameters.PrimaryScreenHeigth}" 
    Width="{Binding SystemParameters.PrimaryScreenWidth}"
    AllowsTransparency="False"
    WindowStartupLocation="CenterScreen"
    ResizeMode="CanResizeWithGrip"
   <Grid/>
</Window>

Now I want to fix some sort of limit in which the user can't resize the window beyond it. 现在我想修复某种限制,用户无法在其外调整窗口大小。 Just to give an example, in Spotify app for Windows desktop, the user can't resize beyond a certain limit. 举一个例子,在用于Windows桌面的Spotify应用程序中,用户无法调整大小超过一定限度。 This is the minimum I can get: 这是我能得到的最低限度:

在此输入图像描述

Thoughts? 思考?

To force a minimum window size, set your MinWidth and MinHeight attributes on the Window : 要强制最小窗口大小,请在Window上设置MinWidth和MinHeight属性:

<Window x:Class="WavePoint_MVVM.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    FontSize="13" 
    FontFamily="Verdana"
    xmlns:local="clr-namespace:WavePoint_MVVM"
    Height="{Binding SystemParameters.PrimaryScreenHeigth}" 
    Width="{Binding SystemParameters.PrimaryScreenWidth}"
    AllowsTransparency="False"
    WindowStartupLocation="CenterScreen"
    ResizeMode="CanResizeWithGrip"
    MinWidth="640"
    MinHeight="480">
   <Grid/>
</Window>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM