2010-08-27 63 views
1

我正在嘗試動畫主窗口,更改寬度和高度。我在主窗口樣式中使用DataTrigger來更改它,但是當我運行它時,首先觸發寬度更改,然後更改高度,我希望它們都同時更改。WPF故事板沒有並行運行動畫

<Storyboard x:Key="TransitToExecution"> 
    <!-- This animation hides the main panel --> 
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Duration="0:0:0.5"> 
     <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="{StaticResource ScreenHeight}"/> 
    </DoubleAnimationUsingKeyFrames> 
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Duration="0:0:0.5"> 
     <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="{StaticResource ScreenWidth}"/> 
    </DoubleAnimationUsingKeyFrames> 
</Storyboard> 

數據觸發很簡單:

<Window.Style> 
    <Style> 
     <Style.Triggers> 
      <DataTrigger Binding="{Binding IsWideScreen}" Value="true" > 
       <DataTrigger.EnterActions> 
        <BeginStoryboard Storyboard="{StaticResource TransitToExecution}"/> 
       </DataTrigger.EnterActions> 
      </DataTrigger> 
     </Style.Triggers> 
    </Style> 
</Window.Style> 

任何想法,爲什麼這兩個動畫不simultaneuosly運行?

感謝

+0

您是否嘗試過交換動畫以查看效果是否獨立於您正在動畫的屬性? – ChrisF 2010-08-27 11:49:40

+0

無論我先放哪個都運行良好,第二個只要突然間就會突然出現。我想知道是否與寬度和高度有關,不能設置在一起 – 2010-08-27 11:52:04

回答

0

我相信,你需要在你的扳機2個BeginStoryboards - 一個寬度,一個高度。

<Storyboard x:Key="TransitToExecutionHeight"> 
    <!-- This animation hides the main panel --> 
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Duration="0:0:0.5"> 
     <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="{StaticResource ScreenHeight}"/> 
    </DoubleAnimationUsingKeyFrames> 
</Storyboard> 
<Storyboard x:Key="TransitToExecutionWidth"> 
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Duration="0:0:0.5"> 
     <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="{StaticResource ScreenWidth}"/> 
    </DoubleAnimationUsingKeyFrames> 
</Storyboard> 

,然後在觸發:

<Window.Style> 
    <Style> 
     <Style.Triggers> 
      <DataTrigger Binding="{Binding IsWideScreen}" Value="true" > 
       <DataTrigger.EnterActions> 
        <BeginStoryboard Storyboard="{StaticResource TransitToExecutionWidth}"/> 
        <BeginStoryboard Storyboard="{StaticResource TransitToExecutionHeight}"/> 
       </DataTrigger.EnterActions> 
      </DataTrigger> 
     </Style.Triggers> 
    </Style> 
</Window.Style> 
+0

不,實際上也不起作用。它似乎可以同時移動窗口的高度和寬度。 – 2010-09-01 09:50:22

+0

我不確定我是否理解你的評論。你的意思是*不能*同時移動高度和寬度?如果這是真的,它可能是一個.NET 4.0或EasingDoubleKeyFrame問題 - 我會推遲到這方面的其他專家,因爲我目前沒有在我面前。我所能說的(目前,無論如何)是我可以在.NET 3.5中使用LinearDoubleKeyFrame同時改變寬度和高度。 – 2010-09-02 14:22:48

1

這似乎並不可能在沒有一些努力,同時要動畫化窗口的同時WidthHeight;解決方案發布了here。或者,您可以將動畫排隊:

<BeginStoryboard HandoffBehavior="Compose"> 
    <Storyboard> 
    <DoubleAnimation Storyboard.TargetName="window name" 
     Storyboard.TargetProperty="Height" 
     From="130" To="600" Duration="0:0:0.5"/> 
    <DoubleAnimation Storyboard.TargetName="window name" 
     Storyboard.TargetProperty="Width" 
     From="300" To="800" Duration="0:0:0.5" BeginTime="0:0:0.5"/> 
    </Storyboard> 
</BeginStoryboard>