gpt4 book ai didi

c# - 如何禁止窗口自动最大化?

转载 作者:行者123 更新时间:2023-11-30 12:15:18 26 4
gpt4 key购买 nike

我有一个窗口,我设置了 ResizeMode=NoResize 并去掉了所有的标题栏和按钮,但问题是当窗口被拖到屏幕顶部时它会最大化,我无法停止它。在我有将窗口最大化和最小化到特定宽度和高度的代码之前,有没有人遇到过这个问题。

这是一个示例代码

<Window xmlns:my="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
x:Class="Custom_title_bar.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" WindowStyle="None" AllowsTransparency="True"
Background="Transparent" mc:Ignorable="d"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
ResizeMode="NoResize"
MinHeight="180" MinWidth="180"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen"
VerticalContentAlignment="Center" VerticalAlignment="Top" WindowState="Normal">
<Grid Name="Main" >
<Border Name="MainWindow" CornerRadius="1" Background="White"
BorderBrush="AliceBlue" MouseDown="move_window" >
<Grid>
<DockPanel>
<DockPanel DockPanel.Dock="Top" Height="26">
<Border CornerRadius="1">
<Border.Background>
<LinearGradientBrush>
<GradientStop Color="White" Offset="0.0"/>
<GradientStop Color="BurlyWood" Offset="0.25"/>
<GradientStop Color="Bisque" Offset="0.5"/>
</LinearGradientBrush>
</Border.Background>
<Grid>
<DockPanel>
<Image MouseDown="MINIMIZE"
Source="/Custom%20title%20bar;component/Images/minimize.png"
Grid.ColumnSpan="4" />
<Image MouseDown="MAX_RESTORE"
Source="/Custom%20title%20bar;component/Images/Restore.png"
Grid.ColumnSpan="4" />
<Image MouseDown="EXIT"
Source="/Custom%20title%20bar;component/Images/close.png" />
<TextBlock/>
</DockPanel>
</Grid>
</Border>
</DockPanel>
</DockPanel>
</Grid>
</Border>
</Grid>

最佳答案

你为什么不设置你的MaxHeight/MaxWidth属性?

因为您的默认大小似乎是 SizeToContent="WidthAndHeight" , 最好设置 MaxHeight/MaxWidthLoaded你的事件Window

this.MaxHeight = this.ActualHeight;
this.MaxWidth = this.ActualWidth;

关于c# - 如何禁止窗口自动最大化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7652035/

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