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

编程入门 行业动态 更新时间:2024-10-26 06:38:02
本文介绍了在当前上下文中不存在"FormWindowState"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在通过Blend和Visual Studio 2012与 WPF合作.每当我尝试使用某些代码时,我都会不断收到这样的错误.对于我的一生,我无法弄清楚.感谢您的任何帮助,任何解释都将很好.

以下是屏幕截图:

要查看更清晰的图像,请右键单击它,然后选择在新标签页中打开"如果有的话.

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

截屏:

错误:错误1"Titan.MainWindow.WindowMaximizeButton"是一个字段",但其用法类似于方法" 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="schemas.microsoft/winfx/2006/xaml/presentation" xmlns:x="schemas.microsoft/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窗体.所以使用像

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

FormWindowState是Windows窗体应用程序的枚举器

您可能正在从Windows Forms开发迁移到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"

在这里,您必须在类中分配一个方法名称,该名称将在您单击按钮时触发.

但是您已经给出了按钮本身的名称

您需要将其设置为

Click="WindowMaximizeButton_Click"

I am working with WPF through blend and Visual Studio 2012. Every time I try to use certain code I keep getting errors like this. For the life of me I can't figure it out. Any help is appreciated, and any explanations would be great.

Here is a screen shot:

Edit: To see the image more clear, right click it and choose "Open in new tab" if available.

Thanks, I updated my code. Now It's giving me a new error.

Screenshot:

Error: Error 1 'Titan.MainWindow.WindowMaximizeButton' is a 'field' but is used like a 'method' C:\Users\Jake\Documents\Expression\Blend 4\Projects\Titan\Titan\MainWindow.xaml 202 91 Titan

XAML Code:

<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="schemas.microsoft/winfx/2006/xaml/presentation" xmlns:x="schemas.microsoft/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>

解决方案

this is WPF. Not windows forms. So use like

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

FormWindowState is an enumerator for Windows Forms Applications

You might be migrating from Windows Forms development to WPF, thats why you're confused

The next error is in this line

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

at here

Click="WindowMaximizeButton"

Here you have to assign a method name inside from the class that will be triggered when you click the button.

But you have given the name of the button itself

You need to set it like

Click="WindowMaximizeButton_Click"

更多推荐

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

本文发布于:2023-11-09 15:11:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572697.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上下文   中不   FormWindowState   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!