在ControlTemplate中分配一个元素作为动画目标 [英] Assign an element as the animation target in a controltemplate

查看:117
本文介绍了在ControlTemplate中分配一个元素作为动画目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想事件触发器设置为我的控制中的一个的ContentTemplate ,我使用的是故事板和DoubleAnimation是嵌套一个DoubleAnimationUsingKeyFrames当我设置的故事板的TargetName为ContentPopup内至极是网格下面我抱,但我得到一个错误,告诉我​​说:

I'm trying to set an event trigger to one of my controls inside a ContentTemplate, i'm using a storyboard and a DoubleAnimation nested with a DoubleAnimationUsingKeyFrames when i set the storyboard TargetName to "ContentPopup" wich is a Grid i hold below, but i get an error telling me that:

名称'ContentPopup'是不是在命名空间System.Windows.Controls.Grid。

在控制模板动画code是:

The animation code on the control template is:

<Grid Margin="0" Width="55" Height="40">
    <Grid.Triggers>
        <EventTrigger RoutedEvent="m:Pushpin.MouseDown">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation Duration="00:00:00.5000000" Storyboard.TargetName="ContentPopup" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" To="1">
                    ...
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Grid.Triggers>
    ...
</Grid>

在网格上,我需要设置动画的code是:

The code on the grid i need to animate is:

<Grid Name="ContentPopup"
      Background="White"
      Opacity="0.85"
      RenderTransformOrigin="0,0">
    <Grid.RenderTransform>
        <TransformGroup>
            <ScaleTransform ScaleX="0" ScaleY="0"/>
            <SkewTransform/>
            <RotateTransform/>
            <TranslateTransform/>
        </TransformGroup>
     </Grid.RenderTransform>
    ...
 </Grid>

MSDN说,做下面的需求,使物体定位的

MSDN says that the following needs to be done to make an object targetable

和网格是一个FrameworkElement的我希望动画在我召唤使用该控件模板我的主窗口上的控件的每一个人经营的,他们是他们中的很多,所以我需要使用模板。
现在的问题是:

and a grid is a FrameworkElement i want the animation to run on every single one of the controls i summon on my main window using this control template, they are a lot of them so i need to use the template. The question is:

有没有元素作为模板的目标?

Is there a way to assign the element as a target in the template?

推荐答案

所以,我发现这样做的正确方法,即使网格是一个 FrameworkElement的您不能从控制模板访问,所以你需要提供一些具有约束力或XAML引用它为了工作,如此具有完全相同的code,而不是仅仅使用 Storyboard.TargetName 使用 Storyboard属性。目标与值:

So i found the right way to do it, even though grid is a FrameworkElement you can't access it from the control template, so you need to provide some binding or XAML reference to it in order to work, so with the same exact code just instead of using the Storyboard.TargetName property using the Storyboard.Target with value:

Storyboard.Target="{Binding ElementName=ContentPopup}"

或也:

Storyboard.Target="{x:Reference Name=ContentPopup}"

它为我工作

这篇关于在ControlTemplate中分配一个元素作为动画目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆