WPF中的临时锁定窗口(重)大小

本文关键字:大小 窗口 锁定 WPF | 更新日期: 2023-09-27 18:16:35

我想锁定在我的应用程序中的某些情况下的大小调整功能,这样做,我试图绑定属性,不允许在某些情况下改变它,但没有成功。

有办法吗?

这是我失败的尝试:XAML:

<Window x:Class="namespace.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Test" MinHeight="300" MinWidth="600" Icon="Icon.ico"
    Height="{Binding WindowsHeight, Mode=TwoWay}" Width="{Binding WindowsWidth, Mode=TwoWay}">

ViewModel:

    private int _windowsHeight = 600;
    private int _windowsWidth = 900;
    public int WindowsHeight
    {
        get { return _windowsHeight; }
        set
        {
            if (_windowsHeight == value) return;
            if (ResizeAvailable) _windowsHeight = value;
            OnPropertyChanged("WindowsHeight");
        }
    }
    public int WindowsWidth
    {
        get { return _windowsWidth; }
        set
        {
            if (_windowsWidth == value) return;
            if (ResizeAvailable) _windowsWidth = value;
            OnPropertyChanged("WindowsWidth");
        }
    }

WPF中的临时锁定窗口(重)大小

为什么不直接将调整模式设置为NoResize呢?

窗口。ResizeMode

this.ResizeMode = System.Windows.ResizeMode.NoResize;