2012-04-17 75 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是不会在这种情况下工作。