2013-08-06 105 views
2

我有以下XAML觸發器和動畫

<Window.Style> 
    <Style TargetType="{x:Type Window}"> 
     <Setter Property="Opacity" Value="0.8" /> 
     <Style.Triggers> 
      <Trigger Property="IsMouseOver" Value="True"> 
       <Setter Property="Opacity" Value="1" /> 
      </Trigger> 
      <EventTrigger RoutedEvent="FrameworkElement.Loaded"> 
       <BeginStoryboard> 
        <BeginStoryboard.Storyboard> 
         <Storyboard> 
          <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity"> 
           <EasingDoubleKeyFrame KeyTime="0" Value="0" /> 
           <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0.8" /> 
          </DoubleAnimationUsingKeyFrames> 
         </Storyboard> 
        </BeginStoryboard.Storyboard> 
       </BeginStoryboard> 
      </EventTrigger> 
     </Style.Triggers> 


    </Style> 
</Window.Style> 

時,我有EventTrigger目前的鼠標懸停觸發不工作。沒有EventTrigger工作正常。我怎麼能有兩個?

回答

4

動畫將不透明度設置爲最終值,您需要給它一個stop的FillBehavior。

<Window.Style> 
     <Style TargetType="{x:Type Window}"> 
      <Setter Property="Opacity" Value="0.8" /> 
      <Style.Triggers> 
       <Trigger Property="IsMouseOver" Value="True"> 
        <Setter Property="Opacity" Value="1" /> 
       </Trigger> 
       <EventTrigger RoutedEvent="FrameworkElement.Loaded"> 
        <BeginStoryboard> 
         <BeginStoryboard.Storyboard> 
          <Storyboard> 
           <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" FillBehavior="Stop"> 
            <EasingDoubleKeyFrame KeyTime="0" Value="0" /> 
            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0.8" /> 
           </DoubleAnimationUsingKeyFrames> 
          </Storyboard> 
         </BeginStoryboard.Storyboard> 
        </BeginStoryboard> 
       </EventTrigger> 
      </Style.Triggers> 


     </Style> 
    </Window.Style>