2012-04-17 72 views
1

玩我想加入到我的ItemsControl動畫的高度在添加時,他們的項目。下面的示例使用觸發器完成了這項工作,但是我無法使它在物品的非固定高度(本例中爲50)下工作。動畫不使用WPF VisualStateManager

<ItemsControl ItemsSource="{Binding Notifications}"> 
<ItemsControl.Resources> 
    <DataTemplate DataType="{x:Type Notifications1:Notification}"> 
     <Button x:Name="ItemButton" 
       ClipToBounds="True" 
       Height="0"> 
      <Button.Template> 
       <ControlTemplate> 
        <Notifications:NotificationTile /> 
       </ControlTemplate> 
      </Button.Template> 
     </Button> 
     <DataTemplate.Triggers> 
      <EventTrigger RoutedEvent="FrameworkElement.Loaded" 
          SourceName="ItemButton"> 
       <BeginStoryboard> 
        <Storyboard> 
         <DoubleAnimation Storyboard.TargetProperty="Height" 
              Storyboard.TargetName="ItemButton" 
              Duration="0:0:0.5" 
              To="50" /> 
        </Storyboard> 
       </BeginStoryboard> 
      </EventTrigger> 
     </DataTemplate.Triggers> 
    </DataTemplate> 
</ItemsControl.Resources> 

然後我試圖使用VisualStateManager來執行動畫,所以瓷磚會增長到他們所需的任何高度。在下面的示例中,項目以正確的大小添加,但不執行動畫。我認爲EventTrigger甚至沒有被解僱?

任何想法非常感謝!

<ItemsControl ItemsSource="{Binding Notifications}" 
      Width="230" 
      ScrollViewer.HorizontalScrollBarVisibility="Hidden" 
      HorizontalContentAlignment="Stretch"> 

<ItemsControl.Resources> 
    <DataTemplate DataType="{x:Type Notifications1:Notification}"> 
     <Button x:Name="ItemButton" 
       ClipToBounds="True" 
       Command="{Binding DataContext.ItemClicked, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" 
       CommandParameter="{Binding}" 
       Visibility="{Binding IsVisible, Converter={StaticResource boolToVisibilityConverter}}"> 
      <Button.Template> 
       <ControlTemplate> 
        <Notifications:NotificationTile /> 
       </ControlTemplate> 
      </Button.Template> 

      <VisualStateManager.CustomVisualStateManager> 
       <is:ExtendedVisualStateManager /> 
      </VisualStateManager.CustomVisualStateManager> 
      <VisualStateManager.VisualStateGroups> 
       <VisualStateGroup is:ExtendedVisualStateManager.UseFluidLayout="True"> 
        <VisualStateGroup.Transitions> 
         <VisualTransition GeneratedDuration="0:0:2" /> 
        </VisualStateGroup.Transitions> 
        <VisualState x:Name="Collapsed"> 
         <Storyboard> 
          <DoubleAnimation Storyboard.TargetProperty="(FrameworkElement.Height)" 
               Storyboard.TargetName="ItemButton" 
               Duration="0" 
               To="0" /> 
         </Storyboard> 
        </VisualState> 
        <VisualState x:Name="Expanded"> 
         <Storyboard> 
          <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" 
                  Storyboard.TargetName="ItemButton"> 
           <DiscreteDoubleKeyFrame KeyTime="0" 
                 Value="NaN" /> 
          </DoubleAnimationUsingKeyFrames> 
         </Storyboard> 
        </VisualState> 
       </VisualStateGroup> 
      </VisualStateManager.VisualStateGroups> 

      <i:Interaction.Triggers> 
       <i:EventTrigger SourceName="ItemButton" 
           EventName="(FrameworkElement.Loaded)"> 
        <is:GoToStateAction StateName="Expanded" /> 
       </i:EventTrigger> 
      </i:Interaction.Triggers> 
     </Button> 
    </DataTemplate> 
</ItemsControl.Resources> 

回答

0

也許這是一個有點題外話,對不起那個。我不確定我完全理解你的問題。 無論如何,這通常不能被推薦到具有動畫只有「爲了」,爲「從」最初設置爲Double.NaN,而DoubleAnimation是不會在這種情況下工作。