2015-08-29 47 views
2

我正在尋找使用WPF在Microsoft PowerPoint中創建類似'wipe'動畫的動畫。在WPF中創建'wipe'動畫

簡單地說,我想讓圖像從1秒鐘左右淡入。

這是XAML我到目前爲止,這一次消失在所有的圖像:

<Window x:Class="WpfApplication2.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:local="clr-namespace:WpfApplication2" 
    mc:Ignorable="d" 
    Title="MainWindow" Height="350" Width="525" Background="Purple" Loaded="Window_Loaded"> 
    <Window.Resources> 
     <Storyboard x:Key="fade"> 
      <DoubleAnimation From="0" To="1" Duration="0:0:1" 
          Storyboard.TargetName="logo" 
          Storyboard.TargetProperty="Opacity"/> 

     </Storyboard> 
    </Window.Resources> 
    <Grid> 
     <Image Source="image.png" x:Name="logo"/> 
    </Grid> 
</Window> 

在後面的代碼,我只是播放動畫時,窗口已加載:

private void Window_Loaded(object sender, RoutedEventArgs e) 
{ 
    BeginStoryboard((Storyboard)FindResource("fade")); 
} 

我需要添加到故事板標記才能使圖像淡入淡出,類似於PowerPoint上的擦除動畫?

回答

1

找到答案我自己從this博客文章。我需要達到我需要的效果的代碼與帖子中的代碼相同,但我不需要第一張圖片。 (UFO.jpg)

<Window x:Class="LearnWPF.WipeEffect.Window1" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="LearnWPF.WipeEffect" Height="500" Width="700" Name="mainWindow"> 
    <Grid> 
     <!--First image not needed.--> 
     <!--<Image Source="Images/UFO.jpg" />--> 
     <Image Source="Images/ladder.jpg"> 
     <Image.OpacityMask> 
      <LinearGradientBrush StartPoint="0,0" EndPoint="1,0"> 
       <GradientStop Offset="0" Color="Black" x:Name="BlackStop"/> 
       <GradientStop Offset="0" Color="Transparent" x:Name="TransparentStop"/> 
      </LinearGradientBrush> 
     </Image.OpacityMask> 
     </Image> 
    </Grid> 
    <Window.Triggers> 
    <EventTrigger RoutedEvent="Window.Loaded"> 
     <EventTrigger.Actions> 
     <BeginStoryboard> 
      <Storyboard> 
      <!--Duration changed to half a second as this is what I need. --> 
      <DoubleAnimation Storyboard.TargetName="TransparentStop" 
          Storyboard.TargetProperty="Offset" By="1" Duration="0:0:0.5" /> 
      <DoubleAnimation Storyboard.TargetName="BlackStop" 
          Storyboard.TargetProperty="Offset" By="1" Duration="0:0:0.5" 
          BeginTime="0:0:0.05" /> 
      </Storyboard> 
     </BeginStoryboard> 
     </EventTrigger.Actions> 
    </EventTrigger> 
    </Window.Triggers> 
    </Window> 
+0

您可以從博客中提取相關的詳細信息,並將它們添加到您的答案中。鏈接將來可能會死亡。 – Gusdor

+0

會做。現在添加代碼。 – Jake

+0

謝謝你。 –