故事板TargetName WPF

问题描述:

我有一个名为SelectionChanging的自定义DependencyProperty的自定义TabControl。那么,我想访问TabItem来为它制作动画,但我不知道如何访问它。这段代码抛出异常说,找不到“tabItem”故事板TargetName WPF

如何从EventTrigger引用此元素“tabItem”?

<DataTemplate x:Key="WorkSpaceTemplate"> 
    <aero:SystemDropShadowChrome> 
     <controls:PinardTabControl IsSynchronizedWithCurrentItem="True" 
        Margin="0" 
        Padding="0" 
        BorderThickness="2" 
        BorderBrush="{StaticResource WorkspaceBorderBrush}" 
        Background="{StaticResource WorkspaceBackgroundBrush}" 
        ItemsSource="{Binding}" SnapsToDevicePixels="True"> 
      <controls:PinardTabControl.Resources> 
       <Style TargetType="{x:Type TabItem}"> 
        <Setter Property="Template" Value="{StaticResource ClosableTabItemTemplate}" /> 
       </Style> 
      </controls:PinardTabControl.Resources> 
      <controls:PinardTabControl.Template> 
       <ControlTemplate TargetType="{x:Type TabControl}"> 
        **<Grid x:Name="tabItem"** 
         ClipToBounds="true" SnapsToDevicePixels="true" KeyboardNavigation.TabNavigation="Local"> 
         <Grid.RowDefinitions> 
          <RowDefinition Height="Auto"/> 
          <RowDefinition Height="*"/> 
         </Grid.RowDefinitions> 
         <TabPanel x:Name="HeaderPanel" IsItemsHost="true" Margin="2,2,2,0" Grid.Row="0" KeyboardNavigation.TabIndex="1" Panel.ZIndex="1"/> 
         <Border x:Name="ContentPanel" CornerRadius="2" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" KeyboardNavigation.DirectionalNavigation="Contained" Grid.Row="1" KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local"> 
          <ContentPresenter x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> 
         </Border> 
        </Grid> 
       </ControlTemplate> 

      </controls:PinardTabControl.Template> 
      <controls:PinardTabControl.Triggers> 
       <EventTrigger RoutedEvent="controls:PinardTabControl.SelectionChanging"> 
        <BeginStoryboard> 
         <Storyboard Name="FormFade"> 
          <DoubleAnimation Name="FormFadeAnimation" 
             **Storyboard.TargetName="tabItem"** 
             Storyboard.TargetProperty="(UIElement.Opacity)" 
             From="0.0" To="1.0" Duration="0:0:0.25" 
             AutoReverse="False" RepeatBehavior="1x" 
            /> 
         </Storyboard> 
        </BeginStoryboard> 
       </EventTrigger> 
      </controls:PinardTabControl.Triggers> 
     </controls:PinardTabControl> 
    </aero:SystemDropShadowChrome> 
</DataTemplate> 

模板内部的元素有不同的范围,您不能从外部访问它们。也许你可以尝试将动画部分移动到模板中(ControlTemplate.Triggers)。

+0

好的H.B.,我会试试那样。谢谢! – 2012-02-06 18:41:26

+0

不客气,很高兴(推测)帮助:) – 2012-02-06 19:04:26