本文介绍了是否有可能使用TemplateBinding在Silverlight中的一个Storyboard?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建在Silverlight自定义控件,我想其中的一个字段时属性更改为动画到DependencyProperty的价值。更具体地讲,我在我的控制模板特定的项目,我想动画每当背景颜色改变背景颜色。所以,我拥有的是:

I'm building a custom control in Silverlight and I want one of the fields to animate to the value of a DependencyProperty when that property is changed. More specifically, I have particular item in my Control Template that I want to animate to the color of the Background whenever the background changes color. So, what I have is:

<ControlTemplate TargetType="local:MyType">
                <Grid x:Name="PART_RootElement">
                    <Grid.Resources>
                        <Storyboard x:Name="PART_FillAnimation">
                            <ColorAnimationUsingKeyFrames
                                 BeginTime="00:00:00"
                                 Storyboard.TargetName="PART_MainPath"
                           Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
                                <EasingColorKeyFrame
                                    x:Name="PATH_FillKeyframe"
                                    KeyTime="00:00:01"
                                    Value="{TemplateBinding Background}"/>
                            </ColorAnimationUsingKeyFrames>
                        </Storyboard>
                    </Grid.Resources>
                    <!-- the rest of the template -->

我引发了自定义控件code动画,但动画开始时,它看起来并不像值被更新。我只是想知道,或如果我失去了一些东西,如果它是在所有可能的应用TemplateBinding资源在我的ControlTemplate。

I'm triggering the animation in the custom control code, but when the animation starts, it doesn't look like the Value is updating. I was just wondering if I'm missing something or if it is at all possible to apply TemplateBinding to resources in my ControlTemplate.

(我目前使用一个变通的手动分配背景的EasingColorKeyFrame价值,但​​TemplateBinding解决方案会这么干净多了。)

(I'm currently using a work-around of manually assigning the Background to the EasingColorKeyFrame Value, but the TemplateBinding solution would be so much cleaner.)

推荐答案

看一看 <一个href=\"http://ex$p$pssionblend.$c$cplex.com/wikipage?title=Behaviors%20and%20Effects&referringTitle=Documentation\"相对=nofollow>防爆pression混合样品 作为一个可能的解决您的问题。有一些,你可以用你的控件模板中创建您寻找的效果交互类。该文档是不是很大,但在对象浏览器的说明应该给你一些更多的线索:)

Have a look at Expression Blend Samples as a possible solution to your problem. There are a number of Interactivity classes that you could use within your ControlTemplate to create the effect your looking for. The documentation is not great, but descriptions in the Object Browser should give you some more clues :)

例如,我有一个列表框的ItemTemplate包含ControlStoryboardAction行为。此行为的触发是一个DataTrigger当一个DataContext字段包含特定值时触发。 (在我的情况时的严重性==高的)触发然后播放的ItemTemplate内的故事板。

For example, I have a ListBox ItemTemplate that contains a ControlStoryboardAction Behaviour. The trigger for this Behaviour is a DataTrigger which fires when a DataContext field contains a specific value. (In my case when Severity=="High") The trigger then Plays a Storyboard within the ItemTemplate.

<i:Interaction.Triggers>
<is:DataTrigger Binding="{Binding Severity, Mode=OneWay}" Value="High">
    <im:ControlStoryboardAction Storyboard="{StaticResource flashLight}" IsEnabled="True" />
</is:DataTrigger>

以下命名空间被引用:


  1. &LT; I: - System.Windows.Interactivity

  2. &LT是: - 防爆pression.Samples.Interactivity(可从上面的链接我使用的是2009年7月释放SL3)

  3. &LT; IM: - Microsoft.Ex pression.Interactivity.Media

  1. <i: - System.Windows.Interactivity
  2. <is: - Expression.Samples.Interactivity (available from the link above. I am using the July 2009 release for SL3)
  3. <im: - Microsoft.Expression.Interactivity.Media

这篇关于是否有可能使用TemplateBinding在Silverlight中的一个Storyboard?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 21:14