WPF 窗口未最小化/最大化

Sha*_*ngh 1 wpf controls wpf-controls

我是一名 WPF 程序员新手。我的问题如下。

我有一个 WPF 应用程序,在主屏幕上,当我单击最大化按钮时,它不会最大化屏幕,而是将其重新定位到左上列。如果我通过单击和拖动来增加/减小屏幕尺寸,则最大化按钮可以正常工作。窗口属性设置如下:

<Window x:Class="MyApp.Home" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        x:Uid="Window_Main" 
        x:Name="HomeWindow" 
        WindowStyle="None" 
        AllowsTransparency="True" 
        WindowStartupLocation="CenterScreen" 
        Margin="0" 
        BorderBrush="Transparent" 
        BorderThickness="0" 
        Title="Home" 
        MinWidth="1000" MinHeight="800"  
        ResizeMode="CanResizeWithGrip" 
        HorizontalAlignment="Stretch" 
        VerticalAlignment="Stretch" 
        SizeToContent="WidthAndHeight" 
        Visibility="Visible" 
        d:DesignHeight="1080" d:DesignWidth="1200">
Run Code Online (Sandbox Code Playgroud)

按钮的 XAML 是:

<Button x:Uid="btnRestore" x:Name="btnRestore" Height="20" Width="20" Style="{DynamicResource Control_WindowControlBoxStyle}"  Margin="5,0,0,0" ToolTip="Toggle Restore" Click="btnRestore_Click" />
Run Code Online (Sandbox Code Playgroud)

btnRestore_Click 的代码很简单:

    private void btnRestore_Click(object sender, RoutedEventArgs e)
    {
        WindowState = WindowState.Maximized;      
    }
Run Code Online (Sandbox Code Playgroud)

我确信我一定犯了一些愚蠢的错误,但无法弄清楚那是什么。看似简单,但却让我感到困惑。任何帮助,将不胜感激。

Rac*_*hel 5

您有SizeToContent="WidthAndHeight",这将使窗口大小调整为窗口中内容的大小。

删除此属性,或者确保标记的第一个子级Window没有设置尺寸