代码之家  ›  专栏  ›  技术社区  ›  MatthiasS

是否可以在Silverlight中的故事板中使用TemplateBinding?

  •  4
  • MatthiasS  · 技术社区  · 15 年前

    我正在Silverlight中构建一个自定义控件,我希望其中一个字段在该属性更改时设置为DependencyProperty值的动画。更具体地说,我的控件模板中有一个特定的项,每当背景改变颜色时,我都希望将其设置为背景颜色的动画。所以,我得到的是:

    <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解决方案要干净得多。)

    1 回复  |  直到 15 年前
        1
  •  0
  •   IsolatedStorage    14 年前

    看一看 Expression Blend Samples 作为解决你问题的可能方法。您可以在ControlTemplate中使用许多交互类来创建所需的效果。文档不是很好,但是对象浏览器中的描述应该会为您提供更多线索:)

    例如,我有一个包含ControlStoryboardAction行为的ListBox项模板。此行为的触发器是一个DataTrigger,它在DataContext字段包含特定值时触发。(就我而言,当 严重性=“高” )然后,触发器在ItemTemplate中播放情节提要。

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

    引用了以下命名空间:

    1. <i: -System.Windows.交互性
    2. <is: -Expression.Samples.interactive(可从上面的链接获得)。我正在使用SL3的2009年7月版本)
    3. <im: -Microsoft.Expression.Interactive.Media公司