首页 > 解决方案 > 为什么我点击按钮后左眼不再眨眼

问题描述

我制作了一个以黄色笑脸为内容的按钮。当鼠标进入右眼时应该眨眼。当布尔属性更改值时,左眼应该眨眼。当我点击这个按钮时,双眼应该眨眼。使用第二个布尔属性,颜色应该从黄色变为红色,微笑的嘴应该变成悲伤的嘴。鼠标输入眨眼工作正常。在我单击按钮之前,布尔属性更改触发器也可以正常工作。当我点击按钮时,两只眼睛都眨了眨眼。但在此之后,布尔属性更改触发器不再起作用!!!!

是什么让我错了?我已经处理这个问题超过一天了。

<Button x:Name="buttonStartStop" Command="StartStop_Command" Grid.Column="1" Width="60" Margin="0, 4, 0, 0">
                <Button.Resources>
                    <Color x:Key="yellow">#FFFF00</Color>
                    <SolidColorBrush x:Key="yellowSCB" Color="{StaticResource yellow}" />
                    <Color x:Key="red">#FF5050</Color>
                    <SolidColorBrush x:Key="redSCB" Color="{StaticResource red}" />
                    <Color x:Key="black">#202020</Color>
                    <SolidColorBrush x:Key="blackSCB" Color="{StaticResource black}" />
                    <Duration x:Key="dur">0:0:0.2</Duration>
                    <system:Double x:Key="smileySize">100.0</system:Double>
                    <system:Double x:Key="smileyEyeSize">20.0</system:Double>

                    <Storyboard x:Key="winkRight">
                        <DoubleAnimation Duration="{StaticResource dur}" To="34" Storyboard.TargetName="eyeRight" Storyboard.TargetProperty="(Canvas.Top)" />
                        <DoubleAnimation Duration="{StaticResource dur}" To="2" Storyboard.TargetName="eyeRight" Storyboard.TargetProperty="Height" />
                        <DoubleAnimation BeginTime="0:0:0.3" Duration="{StaticResource dur}" To="25" Storyboard.TargetName="eyeRight" Storyboard.TargetProperty="(Canvas.Top)" />
                        <DoubleAnimation BeginTime="0:0:0.3" Duration="{StaticResource dur}" To="{StaticResource smileyEyeSize}" Storyboard.TargetName="eyeRight" Storyboard.TargetProperty="Height" />
                    </Storyboard>

                    <Storyboard x:Key="winkLeftB">
                        <DoubleAnimation Duration="{StaticResource dur}" To="34" Storyboard.TargetName="eyeLeft" Storyboard.TargetProperty="(Canvas.Top)" />
                        <DoubleAnimation Duration="{StaticResource dur}" To="2" Storyboard.TargetName="eyeLeft" Storyboard.TargetProperty="Height" />
                        <DoubleAnimation BeginTime="0:0:0.3" Duration="{StaticResource dur}" To="25" Storyboard.TargetName="eyeLeft" Storyboard.TargetProperty="(Canvas.Top)" />
                        <DoubleAnimation BeginTime="0:0:0.3" Duration="{StaticResource dur}" To="{StaticResource smileyEyeSize}" Storyboard.TargetName="eyeLeft" Storyboard.TargetProperty="Height" />
                    </Storyboard>

                    <Storyboard x:Key="winkLeft">
                        <DoubleAnimation Duration="{StaticResource dur}" To="34" Storyboard.TargetProperty="(Canvas.Top)" />
                        <DoubleAnimation Duration="{StaticResource dur}" To="2" Storyboard.TargetProperty="Height" />
                        <DoubleAnimation BeginTime="0:0:0.3" Duration="{StaticResource dur}" To="25" Storyboard.TargetProperty="(Canvas.Top)" />
                        <DoubleAnimation BeginTime="0:0:0.3" Duration="{StaticResource dur}" To="{StaticResource smileyEyeSize}" Storyboard.TargetProperty="Height" />
                    </Storyboard>

                </Button.Resources>
                <Button.Style>
                    <Style TargetType="{x:Type Button}">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate>
                                    <Border x:Name="background" Background="#AAAAAA" BorderBrush="White" BorderThickness="1" CornerRadius="4">
                                        <Viewbox Margin="1">
                                            <Canvas Width="{StaticResource smileySize}" Height="{StaticResource smileySize}">
                                                <Ellipse x:Name="smiley" Width="{StaticResource smileySize}" Height="{StaticResource smileySize}" Fill="{StaticResource yellowSCB}" >
                                                    <Ellipse.Style>
                                                        <Style TargetType="{x:Type Ellipse}">
                                                            <Style.Triggers>
                                                                <DataTrigger Binding="{Binding Path=HeadlineValues.Explode}" Value="True">
                                                                    <DataTrigger.EnterActions>
                                                                        <BeginStoryboard>
                                                                            <Storyboard>
                                                                                <ColorAnimation Duration="{StaticResource dur}" To="{StaticResource red}" Storyboard.TargetProperty="(Fill).(Color)" />
                                                                            </Storyboard>
                                                                        </BeginStoryboard>
                                                                    </DataTrigger.EnterActions>
                                                                    <DataTrigger.ExitActions>
                                                                        <BeginStoryboard>
                                                                            <Storyboard>
                                                                                <ColorAnimation Duration="{StaticResource dur}" To="{StaticResource yellow}" Storyboard.TargetProperty="(Fill).(Color)" />
                                                                            </Storyboard>
                                                                        </BeginStoryboard>
                                                                    </DataTrigger.ExitActions>
                                                                </DataTrigger>
                                                            </Style.Triggers>
                                                        </Style>
                                                    </Ellipse.Style>
                                                    <Ellipse.Effect>
                                                        <DropShadowEffect BlurRadius="10" ShadowDepth="0" Color="{Binding Path=Fill.Color, RelativeSource={RelativeSource AncestorType=Ellipse}}" />
                                                    </Ellipse.Effect>
                                                </Ellipse>
                                                <Ellipse x:Name="eyeLeft" Width="{StaticResource smileyEyeSize}" Height="{StaticResource smileyEyeSize}" Fill="{StaticResource blackSCB}" Canvas.Left="20" Canvas.Top="25">
                                                    <Ellipse.Style>
                                                        <Style TargetType="{x:Type Ellipse}">
                                                            <Style.Triggers>
                                                                <DataTrigger Binding="{Binding Path=HeadlineValues.FieldClick}" Value="True">
                                                                    <DataTrigger.EnterActions>
                                                                        <BeginStoryboard Storyboard="{StaticResource winkLeft}" />
                                                                    </DataTrigger.EnterActions>
                                                                </DataTrigger>
                                                                <DataTrigger Binding="{Binding Path=HeadlineValues.FieldClick}" Value="True">
                                                                    <DataTrigger.ExitActions>
                                                                        <BeginStoryboard Storyboard="{StaticResource winkLeft}" />
                                                                    </DataTrigger.ExitActions>
                                                                </DataTrigger>
                                                            </Style.Triggers>
                                                        </Style>
                                                    </Ellipse.Style>
                                                </Ellipse>
                                                
                                                <Ellipse x:Name="eyeRight" Width="{StaticResource smileyEyeSize}" Height="{StaticResource smileyEyeSize}" Fill="{StaticResource blackSCB}" Canvas.Left="60" Canvas.Top="25" />
                                                
                                                <Path Stroke="{StaticResource blackSCB}" StrokeThickness="10" StrokeStartLineCap="Round" StrokeEndLineCap="Round">
                                                    <Path.Style>
                                                        <Style TargetType="{x:Type Path}">
                                                            <Setter Property="Data">
                                                                <Setter.Value>
                                                                    <PathGeometry FillRule="Nonzero">
                                                                        <PathFigure StartPoint="20, 65" IsClosed="False" IsFilled="False">
                                                                            <BezierSegment Point1="20, 65" Point2="50, 100" Point3="80, 65" />
                                                                        </PathFigure>
                                                                    </PathGeometry>
                                                                </Setter.Value>
                                                            </Setter>
                                                            <Style.Triggers>
                                                                <DataTrigger Binding="{Binding Path=HeadlineValues.Explode}" Value="True">
                                                                    <DataTrigger.EnterActions>
                                                                        <BeginStoryboard>
                                                                            <Storyboard>
                                                                                <PointAnimation Duration="{StaticResource dur}" To="30, 75" Storyboard.TargetProperty="Data.(PathGeometry.Figures)[0].(PathFigure.StartPoint)" />
                                                                                <PointAnimation Duration="{StaticResource dur}" To="30, 75" Storyboard.TargetProperty="Data.(PathGeometry.Figures)[0].(PathFigure.Segments)[0].(BezierSegment.Point1)" />
                                                                                <PointAnimation Duration="{StaticResource dur}" To="50, 55" Storyboard.TargetProperty="Data.(PathGeometry.Figures)[0].(PathFigure.Segments)[0].(BezierSegment.Point2)" />
                                                                                <PointAnimation Duration="{StaticResource dur}" To="70, 75" Storyboard.TargetProperty="Data.(PathGeometry.Figures)[0].(PathFigure.Segments)[0].(BezierSegment.Point3)" />
                                                                            </Storyboard>
                                                                        </BeginStoryboard>
                                                                    </DataTrigger.EnterActions>
                                                                    <DataTrigger.ExitActions>
                                                                        <BeginStoryboard>
                                                                            <Storyboard>
                                                                                <PointAnimation Duration="{StaticResource dur}" To="20, 65" Storyboard.TargetProperty="Data.(PathGeometry.Figures)[0].(PathFigure.StartPoint)" />
                                                                                <PointAnimation Duration="{StaticResource dur}" To="20, 65" Storyboard.TargetProperty="Data.(PathGeometry.Figures)[0].(PathFigure.Segments)[0].(BezierSegment.Point1)" />
                                                                                <PointAnimation Duration="{StaticResource dur}" To="50, 100" Storyboard.TargetProperty="Data.(PathGeometry.Figures)[0].(PathFigure.Segments)[0].(BezierSegment.Point2)" />
                                                                                <PointAnimation Duration="{StaticResource dur}" To="80, 65" Storyboard.TargetProperty="Data.(PathGeometry.Figures)[0].(PathFigure.Segments)[0].(BezierSegment.Point3)" />
                                                                            </Storyboard>
                                                                        </BeginStoryboard>
                                                                    </DataTrigger.ExitActions>
                                                                </DataTrigger>
                                                            </Style.Triggers>
                                                        </Style>
                                                    </Path.Style>
                                                </Path>
                                            </Canvas>
                                        </Viewbox>
                                    </Border>
                                    <ControlTemplate.Triggers>
                                        <EventTrigger RoutedEvent="MouseEnter">
                                            <BeginStoryboard Storyboard="{StaticResource winkRight}" />
                                            <BeginStoryboard>
                                                <Storyboard>
                                                    <ColorAnimation Duration="{StaticResource dur}" To="#BBBBBB" Storyboard.TargetName="background" Storyboard.TargetProperty="Background.Color" />
                                                </Storyboard>
                                            </BeginStoryboard>
                                        </EventTrigger>
                                        <EventTrigger RoutedEvent="MouseLeave">
                                            <BeginStoryboard>
                                                <Storyboard>
                                                    <ColorAnimation Duration="{StaticResource dur}" To="#AAAAAA" Storyboard.TargetName="background" Storyboard.TargetProperty="Background.Color" />
                                                </Storyboard>
                                            </BeginStoryboard>
                                        </EventTrigger>
                                        <EventTrigger RoutedEvent="Button.Click">
                                            <BeginStoryboard Storyboard="{StaticResource winkRight}" />
                                            <BeginStoryboard Storyboard="{StaticResource winkLeftB}" />
                                        </EventTrigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </Button.Style>
            </Button>

标签: wpfbuttondatatrigger

解决方案


推荐阅读