2016-10-20 113 views
0

這裏就是我想要做的事:WPF故事板動畫不是流體

製作控制1可見,使控制2暈倒,在控制1比0.8秒動畫不透明度從1到0。

做到這一點後,立即這樣做:

製作CONTROL1倒塌,使控制2可見,從0上控制2比0.8秒動畫不透明度爲1。

我只是不能讓它變得流暢,我出來的想法。這裏就是我:

<Storyboard x:Key="sb"> 
    <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.8000000" Storyboard.TargetName="MainTabControl" Storyboard.TargetProperty="(UIElement.Visibility)"> 
     <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}"/> 
     <DiscreteObjectKeyFrame KeyTime="00:00:00.8000000" Value="{x:Static Visibility.Collapsed}"/> 
    </ObjectAnimationUsingKeyFrames> 
    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.8000000" Storyboard.TargetName="MainTabControl" Storyboard.TargetProperty="(UIElement.Opacity)"> 
     <LinearDoubleKeyFrame KeyTime="00:00:00" Value="1"/> 
     <LinearDoubleKeyFrame KeyTime="00:00:00.8000000" Value="0"/> 
    </DoubleAnimationUsingKeyFrames> 
    <ObjectAnimationUsingKeyFrames BeginTime="00:00:00.8000000" Duration="00:00:00.8000000" Storyboard.TargetName="SearchProjectsView" Storyboard.TargetProperty="(UIElement.Visibility)"> 
     <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Collapsed}"/> 
     <DiscreteObjectKeyFrame KeyTime="00:00:00.8000000" Value="{x:Static Visibility.Visible}"/> 
    </ObjectAnimationUsingKeyFrames> 
    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.8000000" Duration="00:00:00.8000000" Storyboard.TargetName="SearchProjectsView" Storyboard.TargetProperty="(UIElement.Opacity)"> 
     <LinearDoubleKeyFrame KeyTime="00:00:00.0000000" Value="0"/> 
     <LinearDoubleKeyFrame KeyTime="00:00:00.8000000" Value="1"/> 
    </DoubleAnimationUsingKeyFrames> 
</Storyboard> 
+1

是否有可能發佈的所有代碼或示例項目的拉鍊,這樣很容易讓我們來運行它,並幫助解決的? –

回答

1

它不是從你的問題很清楚,爲什麼你會動畫的同時不透明度和Visbility,但你的問題是,第二控制的可見性的動畫應該立即開始,而不是0.8秒後。

這應該工作:

<Storyboard> 

    <ObjectAnimationUsingKeyFrames 
     Storyboard.TargetName="MainTabControl" Storyboard.TargetProperty="Visibility"> 
     <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/> 
     <DiscreteObjectKeyFrame KeyTime="0:0:0.8" Value="{x:Static Visibility.Collapsed}"/> 
    </ObjectAnimationUsingKeyFrames> 

    <ObjectAnimationUsingKeyFrames 
     Storyboard.TargetName="SearchProjectsView" Storyboard.TargetProperty="Visibility"> 
     <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/> 
     <DiscreteObjectKeyFrame KeyTime="0:0:0.8" Value="{x:Static Visibility.Visible}"/> 
    </ObjectAnimationUsingKeyFrames> 

    <DoubleAnimation 
     Storyboard.TargetName="MainTabControl" Storyboard.TargetProperty="Opacity" 
     From="1" To="0" Duration="0:0:0.8"/> 

    <DoubleAnimation 
     Storyboard.TargetName="SearchProjectsView" Storyboard.TargetProperty="Opacity" 
     From="0" To="1" BeginTime="0:0:0.8" Duration="0:0:0.8"/> 

</Storyboard> 
+0

因爲如果控件不透明度爲0,它仍然在窗口上繪製。它可能是完全透明的,但阻止它下面的完全可見的元素。 – shady

+0

我以爲在WPF中打擊測試會忽略透明像素。 –

+0

@BradleyUffner不,它不會忽略它們。它只會忽略'null'背景填充筆刷。 – Clemens