是否可以从数据模板内的代码(.cs文件)开始创建故事板。以下代码不起作用请告诉我。
<HubSection Width="800" x:Name="Section2" Header="Section 2" Foreground="Black">
<DataTemplate x:Name="DataTemplateNotificaiton" >
<Grid Background="White" Width="700" Height="500" Margin="-20" >
<Canvas x:Name="canvas" Margin="0,302,0,-302" Canvas.ZIndex="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" RenderTransformOrigin="0.5,0.5" >
<Canvas.Resources>
<Storyboard x:Name="TileAnimation">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="canvas">
<EasingDoubleKeyFrame KeyTime="0" Value="-1.5"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="-252"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Canvas.Resources>
<Canvas.RenderTransform>
<CompositeTransform/>
</Canvas.RenderTransform>
<TextBlock x:Name="panel1" Margin="30,30,0,0" Text="sdasdasdasd" FontFamily="Segoe WP Light" FontSize="32" >
<TextBlock.RenderTransform>
<TranslateTransform/>
</TextBlock.RenderTransform>
</TextBlock>
<TextBlock x:Name="panel2" Margin="30,7,0,0" TextWrapping="Wrap" Text="adasdasdasdasd" FontFamily="Segoe WP Light" FontSize="22" Canvas.Top="98">
<TextBlock.RenderTransform>
<TranslateTransform/>
</TextBlock.RenderTransform>
</TextBlock>
</Canvas>
</Grid>
</DataTemplate>
</HubSection>
c#代码背后:
Storyboard anim = (Storyboard)FindName("TileAnimation");
anim.Begin();
答案 0 :(得分:0)
是的,但是当您想要保持代码可读时,这很复杂而且不推荐。 我建议的是,开发一个userControl,其中包含模板中当前的所有内容,然后在该控件中设计动画。 您可以在datatemplate中轻松添加此新控件,而不是上面的代码。这使得测试控件也更容易。
HTH-奥利弗