我的Silverlight应用中有一个奇怪的行为,我想知道如何修复它。
我有一组按钮可根据场景需求更改可见性。但是,在更改按钮的可见性几次之后,它们会以“MouseOver”状态堆叠。我可以告诉它,因为我有一个故事板分配给鼠标状态,它在'MouseOver'状态下永远运行。我想知道什么是解决方案。以下是我正在使用的代码。提前谢谢!
按钮:
<Button x:Name="Button1" Style="{StaticResource Button1Style}" Click="OpenGrid1"/>
我控制可见性的代码:
private void OpenGrid1(object sender, System.Windows.RoutedEventArgs e)
{
this.Book.RightPageIndex = 1;
this.Button1.Visibility = System.Windows.Visibility.Visible;
this.Button2.Visibility = System.Windows.Visibility.Collapsed;
this.Button2ImageAbove.Visibility = System.Windows.Visibility.Visible;
this.Button3.Visibility = System.Windows.Visibility.Collapsed;
this.Button3ImageAbove.Visibility = System.Windows.Visibility.Visible;
this.Button4.Visibility = System.Windows.Visibility.Collapsed;
this.Button4ImageAbove.Visibility = System.Windows.Visibility.Visible;
}
一个按钮的样式:
<Style x:Key="Button1Style" TargetType="Button">
<Setter Property="Background" Value="#FF1F3B53"/>
<Setter Property="Foreground" Value="#FF000000"/>
<Setter Property="Padding" Value="3"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="BorderBrush">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFA3AEB9" Offset="0"/>
<GradientStop Color="#FF8399A9" Offset="0.375"/>
<GradientStop Color="#FF718597" Offset="0.375"/>
<GradientStop Color="#FF617584" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid x:Name="grid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="37" />
</Grid.ColumnDefinitions>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0:0:0.7" To="MouseOver">
<VisualTransition.GeneratedEasingFunction>
<BackEase EasingMode="EaseIn"/>
</VisualTransition.GeneratedEasingFunction>
<Storyboard RepeatBehavior="Forever" >
<PointAnimation Duration="0:0:1.5" To="3.199,0.922" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.StartPoint)" Storyboard.TargetName="borderForward"/>
<PointAnimation Duration="0:0:1.5" To="7.536,1.686" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.EndPoint)" Storyboard.TargetName="borderForward"/>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="border">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualTransition>
<VisualTransition From="Pressed" GeneratedDuration="0" To="Normal">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="border">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualTransition>
<VisualTransition From="MouseOver" GeneratedDuration="0" To="Normal">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="border">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualTransition>
</VisualStateGroup.Transitions>
<VisualState x:Name="Normal">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="border">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="MouseOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="border">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed"/>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="grid">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="Focused"/>
<VisualState x:Name="Unfocused"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Image x:Name="ForwardEduIdleback" Source="Images/ForwardEduIdle.png" Stretch="Fill" Width="37" Height="111"/>
<Border x:Name="border" BorderThickness="1" util:Clip.ToBounds="true" CornerRadius="12" Width="35" Height="109" Margin="-5,-4,0,0" Visibility="Collapsed" >
<Border x:Name="borderForward" CornerRadius="10" util:Clip.ToBounds="true" Width="50" Margin="-18,0,0,0" >
<Border.Background>
<LinearGradientBrush EndPoint="-1.564,0.155" StartPoint="-5.901,-0.609">
<GradientStop Color="#69FFFFFF" Offset="0.432"/>
<GradientStop Color="Transparent" Offset="0.797"/>
<GradientStop Color="Transparent" Offset="0.127"/>
</LinearGradientBrush>
</Border.Background>
</Border>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>