网上很多说用hook还有写乱七八糟一堆代码。我这唯一找到一个很好的方案:
xaml文件加入这句代码:完美解决
private void ButtonMax_Click(object sender, RoutedEventArgs e)
{
if (this.WindowState == WindowState.Maximized)
{
this.WindowState = WindowState.Normal;
}
else if (this.WindowState == WindowState.Normal)
{
this.WindowState = WindowState.Maximized;
//代码在这
this.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
this.MaxWidth = SystemParameters.MaximizedPrimaryScreenWidth;
}
}
或者在xaml文件里加上这句
<Window x:Class="Working.Ui.WindowManagement"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="" Height="960" Width="1280" WindowStyle="None" MaxWidth="{StaticResource {x:Static SystemParameters.MaximizedPrimaryScreenWidthKey}}" MaxHeight="{StaticResource {x:Static SystemParameters.MaximizedPrimaryScreenHeightKey}}">