Xaml 在Windows Phone 8中调用样式内部对象上的动画

Xaml 在Windows Phone 8中调用样式内部对象上的动画,xaml,silverlight,windows-phone-8,Xaml,Silverlight,Windows Phone 8,我在Panorama页面中有自己的PanningTitleLayer样式,我正在尝试将动画设置为该样式中的对象。但从后面的代码中,我看不到像ClockAnimation或TextCoffeeTimerFirst这样的对象 所以我不能从代码隐藏调用ClockAnimation.Begin()。我可以直接打电话给CoffeePanningTitleLayerStyle,但我也无法访问文本CoffeeTimerFirst等 问题是-我应该如何从我的样式中调用对象的动画 <phone:PhoneA

我在Panorama页面中有自己的PanningTitleLayer样式,我正在尝试将动画设置为该样式中的对象。但从后面的代码中,我看不到像ClockAnimation或TextCoffeeTimerFirst这样的对象

所以我不能从代码隐藏调用ClockAnimation.Begin()。我可以直接打电话给CoffeePanningTitleLayerStyle,但我也无法访问文本CoffeeTimerFirst等

问题是-我应该如何从我的样式中调用对象的动画

<phone:PhoneApplicationPage.Resources>
        <Style x:Key="CoffeePanningTitleLayerStyle" TargetType="Primitives:PanningTitleLayer">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Primitives:PanningTitleLayer">
                        <StackPanel x:Name="PanningStackPanel" Orientation="Horizontal">
                            <StackPanel.Resources>
                                <Storyboard x:Name="ClockAnimation">
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" Storyboard.TargetName="TextCoffeeTimerFirst">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="1"/>
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0.1" Value="4"/>
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0.2" Value="8"/>
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0.3" Value="2"/>
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0.4" Value="9"/>
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0.5" Value="0"/>
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0.6" Value="5"/>
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0.7" Value="3"/>
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0.8" Value="7"/>
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0.9" Value="6"/>
                                    </ObjectAnimationUsingKeyFrames>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="TextCoffeeTimerFirst">
                                        <EasingDoubleKeyFrame KeyTime="0" Value="0">
                                            <EasingDoubleKeyFrame.EasingFunction>
                                                <BounceEase EasingMode="EaseIn" Bounces="9" Bounciness="-2"/>
                                            </EasingDoubleKeyFrame.EasingFunction>
                                        </EasingDoubleKeyFrame>
                                        <EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="15">
                                            <EasingDoubleKeyFrame.EasingFunction>
                                                <BounceEase EasingMode="EaseIn" Bounces="9" Bounciness="-2"/>
                                            </EasingDoubleKeyFrame.EasingFunction>
                                        </EasingDoubleKeyFrame>
                                        <EasingDoubleKeyFrame KeyTime="0:0:0.9" Value="0">
                                            <EasingDoubleKeyFrame.EasingFunction>
                                                <BounceEase EasingMode="EaseIn" Bounces="9" Bounciness="-2"/>
                                            </EasingDoubleKeyFrame.EasingFunction>
                                        </EasingDoubleKeyFrame>
                                    </DoubleAnimationUsingKeyFrames>
                                </Storyboard>
                            </StackPanel.Resources>
                            <StackPanel.RenderTransform>
                                <TransformGroup>
                                    <TranslateTransform x:Name="PanningTransform"/>
                                    <TranslateTransform x:Name="LocalTransform"/>
                                </TransformGroup>
                            </StackPanel.RenderTransform>
                            <Border x:Name="LeftWraparound"/>
                            <StackPanel>
                                <ContentPresenter x:Name="ContentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Canvas.ZIndex="1" Margin="0,12"/>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock x:Name="TextCoffeeTimerFirst" Text="12" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="80" Foreground="#FFB93325" FontFamily="/TAB.WindowsPhone;component/Fonts/BNR.ttf#Bebas Neue Bold" RenderTransformOrigin="0.5,0.5" Width="60" TextAlignment="Right">
                                                            <TextBlock.RenderTransform>
                                                                <CompositeTransform/>
                                                            </TextBlock.RenderTransform>
                                                        </TextBlock>
                                </StackPanel>
                            </StackPanel>
                            <Border x:Name="RightWraparound"/>
                        </StackPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>


VisualTreeHelper可能是一个解决方案,但在现实中:如果情节提要与视觉状态一起使用,则仅将其放入样式中。其他想法:可以使用触发器(行为)这会触发你的动画。@kaiburmummed-hmm所以如果我想在我的文本框中使用像trigger这样的视觉状态-可以接受吗?你需要检查原始控件模板中有哪些状态可用。默认情况下,只能使用这些选项。我认为winRT中不支持样式触发器。