Animation 可以在Silverlight的故事板中使用TemplateBinding吗?
我正在Silverlight中构建一个自定义控件,我希望其中一个字段在属性更改时设置为DependencyProperty的值。更具体地说,我的控件模板中有一个特定的项目,每当背景颜色改变时,我都希望将其设置为背景颜色的动画。因此,我得到的是:Animation 可以在Silverlight的故事板中使用TemplateBinding吗?,animation,silverlight-3.0,custom-controls,templatebinding,Animation,Silverlight 3.0,Custom Controls,Templatebinding,我正在Silverlight中构建一个自定义控件,我希望其中一个字段在属性更改时设置为DependencyProperty的值。更具体地说,我的控件模板中有一个特定的项目,每当背景颜色改变时,我都希望将其设置为背景颜色的动画。因此,我得到的是: <ControlTemplate TargetType="local:MyType"> <Grid x:Name="PART_RootElement"> &l
<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 -->
我在自定义控制代码中触发动画,但是当动画开始时,它看起来不像是在更新值。我只是想知道我是否遗漏了什么,或者是否有可能将TemplateBinding应用于ControlTemplate中的资源
(我目前正在使用手动将背景指定给EasingColorKeyFrame值的变通方法,但TemplateBinding解决方案会更干净。)看看作为解决问题的可能方法。您可以在ControlTemplate中使用许多交互类来创建所需的效果。文档不是很好,但对象浏览器中的描述应该会给您提供更多线索:)
例如,我有一个包含ControlStoryboard动作行为的ListBox ItemTemplate。此行为的触发器是DataTrigger,当DataContext字段包含特定值时触发。(在我的例子中,严重性=“高”)触发器然后在ItemTemplate中播放情节提要
<i:Interaction.Triggers>
<is:DataTrigger Binding="{Binding Severity, Mode=OneWay}" Value="High">
<im:ControlStoryboardAction Storyboard="{StaticResource flashLight}" IsEnabled="True" />
</is:DataTrigger>
引用了以下名称空间: