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

时间:2016-09-03 01:11:30

标签: 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:local="clr-namespace:WavePoint_MVVM"
    Height="{Binding SystemParameters.PrimaryScreenHeigth}" 
    Width="{Binding SystemParameters.PrimaryScreenWidth}"
    AllowsTransparency="False"
    WindowStartupLocation="CenterScreen"
    ResizeMode="CanResizeWithGrip"
   <Grid/>
</Window>

现在我想修复某种限制,用户无法在窗口之外调整窗口大小。举一个例子,在用于Windows桌面的Spotify应用程序中,用户无法调整大小超过一定限度。这是我能得到的最低限度:

enter image description here

思考?

1 个答案:

答案 0 :(得分:3)

要强制使用最小窗口大小,请在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>