C# 如何设置窗口的大小限制?
假设我的窗口有一个xaml,如下所示:C# 如何设置窗口的大小限制?,c#,wpf,xaml,C#,Wpf,Xaml,假设我的窗口有一个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:
<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>
现在我想修正一些限制,用户不能将窗口的大小调整到超出它的范围。举个例子,在用于Windows桌面的Spotify应用程序中,用户的大小不能超过某个限制。这是我能得到的最低限度:
想法 要强制设置最小窗口大小,请在窗口上设置MinWidth和MinHeight属性: 注意SizeToContent=宽度和高度选项。如果也在窗口上设置,则按建议设置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>