故事板TargetName WPF

时间:2012-02-06 18:26:51

标签: c# wpf xaml animation

我有一个自定义TabControl,其自定义DependencyProperty名为SelectionChanging。好吧,我想访问TabItem来动画它,但我不知道如何访问它。此代码抛出一个异常,说无法找到“tabItem”

如何从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>

1 个答案:

答案 0 :(得分:3)

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