gpt4 book ai didi

c# - WPF中的临时锁定窗口(重新)大小

转载 作者:行者123 更新时间:2023-12-03 10:23:02 24 4
gpt4 key购买 nike

在某些情况下,我想在我的应用程序中锁定调整大小功能,为此我尝试对属性进行数据绑定(bind),并且不允许在某些情况下更改它,但没有成功。

有没有办法这样做?

这是我不成功的尝试:
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}">

View 模型:
    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");
}
}

最佳答案

为什么不将调整大小模式设置为 NoResize?

Window.ResizeMode

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

关于c# - WPF中的临时锁定窗口(重新)大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25143518/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com