'FormWindowState' 当前上下文中不存在

'FormWindowState' Does Not Exist In the Current Context

我正在通过 blend 和 Visual Studio 2012 使用 WPF。每次我尝试使用某些代码时,我都会不断收到这样的错误。对于我的生活,我无法弄清楚。感谢任何帮助,任何解释都会很棒。

这是一个屏幕截图:

编辑:要使图像更清晰,请右键单击它并选择“在新选项卡中打开”(如果可用)。

谢谢,我更新了我的代码。现在它给了我一个新的错误。

截图:

错误:错误 1 ​​'Titan.MainWindow.WindowMaximizeButton' 是一个 'field' 但用法与 'method' C:\Users\Jake\Documents\Expression\Blend 4\Projects\Titan\Titan\MainWindow.xaml 202 91 泰坦

XAML代码:

        <Button x:Name="WindowMaximizeButton" Content="Button" Width="14.333" HorizontalAlignment="Right" VerticalAlignment="Top" Style="{DynamicResource WindowMaximizeButton}" Click="WindowMaximizeButton" Margin="0,0,48.998,0">

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
    x:Class="Titan.MainWindow"
    x:Name="Titan"
    Title="Titan"
    Width="880" Height="474" WindowStyle="None" WindowState="Maximized" WindowStartupLocation="CenterScreen" Background="#FF0F0F0F">

    <Window.Resources>
        <Style x:Key="ButtonFocusVisual">
            <Setter Property="Control.Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <LinearGradientBrush x:Key="ButtonNormalBackground" EndPoint="0,1" StartPoint="0,0">
            <GradientStop Color="#F3F3F3" Offset="0"/>
            <GradientStop Color="#EBEBEB" Offset="0.5"/>
            <GradientStop Color="#DDDDDD" Offset="0.5"/>
            <GradientStop Color="#CDCDCD" Offset="1"/>
        </LinearGradientBrush>
        <SolidColorBrush x:Key="ButtonNormalBorder" Color="#FF707070"/>
        <Style x:Key="WindowExitButton" TargetType="{x:Type Button}">
            <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
            <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
            <Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Padding" Value="1"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <ControlTemplate.Resources>
                            <Storyboard x:Key="MouseOver">
                                <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="rectangle">
                                    <EasingColorKeyFrame KeyTime="0:0:0.2" Value="Maroon"/>
                                </ColorAnimationUsingKeyFrames>
                            </Storyboard>
                        </ControlTemplate.Resources>
                        <Grid x:Name="grid" Height="20" Margin="-14,0,-3,0" Width="Auto">
                            <Rectangle x:Name="rectangle" Stroke="Black">
                                <Rectangle.Fill>
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                        <GradientStop Color="#FF210000" Offset="0.978"/>
                                        <GradientStop Color="#FF4D0000"/>
                                    </LinearGradientBrush>
                                </Rectangle.Fill>
                            </Rectangle>
                            <Image x:Name="image" Source="appbar.close.png" Margin="-5,-3.5,-4.5,-3.5"/>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsKeyboardFocused" Value="true"/>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Trigger.ExitActions>
                                    <RemoveStoryboard BeginStoryboardName="MouseOver_BeginStoryboard"/>
                                </Trigger.ExitActions>
                                <Trigger.EnterActions>
                                    <BeginStoryboard x:Name="MouseOver_BeginStoryboard" Storyboard="{StaticResource MouseOver}"/>
                                </Trigger.EnterActions>
                            </Trigger>
                            <Trigger Property="ToggleButton.IsChecked" Value="true"/>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="#ADADAD"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="WindowMaximizeButton" TargetType="{x:Type Button}">
            <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
            <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
            <Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Padding" Value="1"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <ControlTemplate.Resources>
                            <Storyboard x:Key="MouseOver">
                                <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="rectangle">
                                    <EasingColorKeyFrame KeyTime="0:0:0.2" Value="Maroon"/>
                                </ColorAnimationUsingKeyFrames>
                            </Storyboard>
                        </ControlTemplate.Resources>
                        <Grid x:Name="grid" Height="20" Margin="-14,0,-3,0" Width="Auto">
                            <Rectangle x:Name="rectangle" Stroke="Black">
                                <Rectangle.Fill>
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                        <GradientStop Color="#FF210000" Offset="0.978"/>
                                        <GradientStop Color="#FF4D0000"/>
                                    </LinearGradientBrush>
                                </Rectangle.Fill>
                            </Rectangle>
                            <Image x:Name="image" Source="appbar.tablet.windows.png" Margin="-5,-3.5,-4.5,-3.5"/>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsKeyboardFocused" Value="true"/>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Trigger.ExitActions>
                                    <RemoveStoryboard BeginStoryboardName="MouseOver_BeginStoryboard"/>
                                </Trigger.ExitActions>
                                <Trigger.EnterActions>
                                    <BeginStoryboard x:Name="MouseOver_BeginStoryboard" Storyboard="{StaticResource MouseOver}"/>
                                </Trigger.EnterActions>
                            </Trigger>
                            <Trigger Property="ToggleButton.IsChecked" Value="true"/>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="#ADADAD"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="WindowMinimizeButton" TargetType="{x:Type Button}">
            <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
            <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
            <Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Padding" Value="1"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <ControlTemplate.Resources>
                            <Storyboard x:Key="MouseOver">
                                <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="rectangle">
                                    <EasingColorKeyFrame KeyTime="0:0:0.2" Value="Maroon"/>
                                </ColorAnimationUsingKeyFrames>
                            </Storyboard>
                        </ControlTemplate.Resources>
                        <Grid x:Name="grid" Height="20" Margin="-14,0,-3,0" Width="Auto">
                            <Rectangle x:Name="rectangle" Stroke="Black">
                                <Rectangle.Fill>
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                        <GradientStop Color="#FF210000" Offset="0.978"/>
                                        <GradientStop Color="#FF4D0000"/>
                                    </LinearGradientBrush>
                                </Rectangle.Fill>
                            </Rectangle>
                            <Image x:Name="image" Source="appbar.window.minimize.png" Margin="-5,-3.5,-4.5,-3.5" Opacity="0.995"/>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsKeyboardFocused" Value="true"/>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Trigger.ExitActions>
                                    <RemoveStoryboard BeginStoryboardName="MouseOver_BeginStoryboard"/>
                                </Trigger.ExitActions>
                                <Trigger.EnterActions>
                                    <BeginStoryboard x:Name="MouseOver_BeginStoryboard" Storyboard="{StaticResource MouseOver}"/>
                                </Trigger.EnterActions>
                            </Trigger>
                            <Trigger Property="ToggleButton.IsChecked" Value="true"/>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="#ADADAD"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Window.Triggers>
        <EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="WindowExitButton"/>
    </Window.Triggers>

    <Grid x:Name="LayoutRoot">
        <Rectangle Height="84" VerticalAlignment="Top">
            <Rectangle.Effect>
                <DropShadowEffect BlurRadius="25" Opacity="0.495"/>
            </Rectangle.Effect>
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="1"/>
                    <GradientStop Color="#FF101010"/>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
        <Menu Height="35" VerticalAlignment="Top" Background="{x:Null}" Margin="0,49,0,0"/>
        <Button x:Name="WindowExitButton" Content="Button" Width="31" HorizontalAlignment="Right" VerticalAlignment="Top" Style="{DynamicResource WindowExitButton}" Click="WindowExitButton_Click" Margin="0,0,2,0">
            <Button.Background>
                <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                    <GradientStop Color="#FFF3F3F3" Offset="0"/>
                    <GradientStop Color="#FFEBEBEB" Offset="0.5"/>
                    <GradientStop Color="#FFDDDDDD" Offset="0.5"/>
                    <GradientStop Color="#FFCDCDCD" Offset="1"/>
                </LinearGradientBrush>
            </Button.Background>
        </Button>
        <Button x:Name="WindowMaximizeButton" Content="Button" Width="14.333" HorizontalAlignment="Right" VerticalAlignment="Top" Style="{DynamicResource WindowMaximizeButton}" Click="WindowExitButton_Click" Margin="0,0,48.998,0">
            <Button.Background>
                <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                    <GradientStop Color="#FFF3F3F3" Offset="0"/>
                    <GradientStop Color="#FFEBEBEB" Offset="0.5"/>
                    <GradientStop Color="#FFDDDDDD" Offset="0.5"/>
                    <GradientStop Color="#FFCDCDCD" Offset="1"/>
                </LinearGradientBrush>
            </Button.Background>
        </Button>
        <Button x:Name="WindowMinimizeButton" Content="Button" Width="14.333" HorizontalAlignment="Right" VerticalAlignment="Top" Style="{DynamicResource WindowMinimizeButton}" Click="WindowExitButton_Click" Margin="0,0,79.332,0">
            <Button.Background>
                <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                    <GradientStop Color="#FFF3F3F3" Offset="0"/>
                    <GradientStop Color="#FFEBEBEB" Offset="0.5"/>
                    <GradientStop Color="#FFDDDDDD" Offset="0.5"/>
                    <GradientStop Color="#FFCDCDCD" Offset="1"/>
                </LinearGradientBrush>
            </Button.Background>
        </Button>
    </Grid>
</Window>

这是 WPF。不是 windows 表格。所以使用 like

this.WindowState = System.Windows.WindowState.Normal;

FormWindowState 是 Windows Forms Applications

的枚举器

您可能正在从 Windows 表单开发迁移到 WPF,这就是您感到困惑的原因

下一个错误在这一行

<Button x:Name="WindowMaximizeButton" Content="Button" Width="14.333" HorizontalAlignment="Right" VerticalAlignment="Top" Style="{DynamicResource WindowMaximizeButton}" Click="WindowMaximizeButton" Margin="0,0,48.998,0">

在这里

 Click="WindowMaximizeButton" 

这里你必须在class里面分配一个方法名,当你点击按钮时会触发它。

但是你给了按钮本身的名字

你需要这样设置

Click="WindowMaximizeButton_Click"