我正在使用 WPF通过blend和Visual Studio 2012 。每次我尝试使用某些代码时,我都会遇到这样的错误。对于我的生活,我无法弄清楚。任何帮助表示赞赏,任何解释都会很棒。
这是一个截图:
编辑:要更清晰地查看图像,请右键单击它并选择“在新标签页中打开”(如果有)。
谢谢,我更新了我的代码。现在它给了我一个新的错误。
截图:
错误:错误1'Titan.MainWindow.WindowMaximizeButton'是一个'字段',但用作'方法'C:\ Users \ Jake \ Documents \ Expression \ Blend 4 \ Projects \ Titan \ Titan \ MainWindow.xaml 202 91 Titan
<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>
答案 0 :(得分:1)
这是WPF。不是窗体。所以请使用
this.WindowState = System.Windows.WindowState.Normal;
FormWindowState是Windows窗体应用程序的枚举器
您可能正在从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"
在这里,你必须从类中分配一个方法名称,当你点击按钮时它将被触发。
但是您已经给出了按钮本身的名称
您需要将其设置为
Click="WindowMaximizeButton_Click"