我有一個窗口,我已經設置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>
能告訴你什麼是MOUSE_MOVE()呢?你的Windows版本是什麼? –
正在使用user32.dll函數,但將其更改爲this.DragMove它幫助我解決了這個問題。 –