2013-04-25 86 views
0

我想爲彈出的邊框設置動畫,這個邊框會在5秒內可見,然後摺疊。當邊框可見時,它僅在5秒內可見,然後摺疊。每當邊框可見時,都會重複此操作。我試過了,但它只出現過一次。有人可以向我解釋我所犯的錯誤嗎?如何查看邊界/彈出5秒?

這裏是我已經實現

<Grid.Resources> 
     <Style x:Key="NotificationStyle" TargetType="{x:Type Border}"> 
      <Style.Triggers> 
       <Trigger Property="Visibility" Value="Visible"> 
        <Trigger.EnterActions> 
         <BeginStoryboard x:Name="NotificationStoryBoard"> 
          <Storyboard > 
           <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Visibility)"> 
            <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}"/> 

            <DiscreteObjectKeyFrame KeyTime="00:00:05" Value="{x:Static Visibility.Collapsed}"/> 
           </ObjectAnimationUsingKeyFrames> 
          </Storyboard> 
         </BeginStoryboard> 
        </Trigger.EnterActions> 
       </Trigger> 
      </Style.Triggers> 
     </Style> 
    </Grid.Resources> 

這裏是邊境的風格...

<Border Name="NotifciationPopUp" Background="White" Height="80" Width="200" BorderBrush="Gray" BorderThickness="1" VerticalAlignment="Bottom" HorizontalAlignment="Left" Visibility="Collapsed" Margin="10,0,0,10" Style="{StaticResource NotificationStyle}"> 

回答

0

我意識到隱藏邊框以這樣的方式:

風格:

<Style x:Key="NotificationStyle" TargetType="{x:Type Border}"> 
    <Style.Triggers> 
     <Trigger Property="Visibility" Value="Visible"> 
      <Trigger.EnterActions> 
       <BeginStoryboard> 
        <Storyboard> 
         <DoubleAnimation Storyboard.TargetProperty="Opacity" BeginTime="0:0:0" From="0.0" To="1.0" Duration="0:0:1.0" /> 
         <DoubleAnimation Storyboard.TargetProperty="Opacity" BeginTime="0:0:5" From="1.0" To="0.0" Duration="0:0:1.0" /> 
        </Storyboard> 
       </BeginStoryboard> 
      </Trigger.EnterActions> 
     </Trigger> 
    </Style.Triggers> 
</Style> 

G排除:

<Grid> 
    <Border Name="MyBorder" Width="100" Visibility="Hidden" Height="50" BorderThickness="2" BorderBrush="OrangeRed" Style="{StaticResource NotificationStyle}"> 
     <TextBlock Text="Some information" TextAlignment="Center" VerticalAlignment="Center" /> 
    </Border> 

    <ToggleButton Name="MyButton" Content="Show border" Width="100" Height="30" VerticalAlignment="Bottom" Click="Button_Click" /> 
</Grid> 

在代碼:

private void Button_Click(object sender, RoutedEventArgs e) 
{    
    if (MyButton.IsChecked == true) 
    { 
     MyBorder.Visibility = System.Windows.Visibility.Visible; 
    } 

    if (MyButton.IsChecked == false) 
    { 
     MyBorder.Visibility = System.Windows.Visibility.Hidden; 
    } 
} 

從他的實驗,我的理解是,如果在動畫中曾經使用的屬性,然後使用它從動畫的觸發器是唯一可能的。因此,我沒有收到的財產的訪問代碼。

此外,控制的使用Visibility = Collapsed,他不接收來自系統的消息,動畫將無法工作。雖然屬性「隱藏」應該帶消息,但我沒有像動畫一樣工作,所以在示例中我使用了不透明度