【发布时间】:2014-12-22 22:34:43
【问题描述】:
我想在 WP8 应用程序中创建选取框效果。 为此,我将 StackPanel 放在 ScrollViewer 中,并尝试在 TranslateTransform.X 属性上使用 DoubleAnimation。
代码:
<phone:PhoneApplicationPage.Resources>
<Storyboard x:Name="Scroll" RepeatBehavior="Forever" AutoReverse="True">
<DoubleAnimation From="0" To="100" Storyboard.TargetName="transform" Storyboard.TargetProperty="X" Duration="0:0:5" />
</Storyboard>
</phone:PhoneApplicationPage.Resources>
<Grid x:Name="LayoutRoot">
...
<ScrollViewer Height="80" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Hidden">
<StackPanel Orientation="Horizontal">
<StackPanel.RenderTransform>
<TranslateTransform x:Name="transform" />
</StackPanel.RenderTransform>
<Image Source="/Assets/logo1.png"></Image>
<Image Source="/Assets/logo2.png"></Image>
<Image Source="/Assets/logo3.png"></Image>
<Image Source="/Assets/logo4.png"></Image>
<Image Source="/Assets/logo5.png"></Image>
</StackPanel>
</ScrollViewer>
</Grid>
不幸的是,当从页面 Loaded 事件处理程序中的代码隐藏调用 Scroll.Begin() 时,我遇到了异常:System.InvalidOperationException:无法解析 TargetName变换。
我做错了什么? 当我将 StackPanel 直接放在 LayoutRoot 中时动画会运行,但当它是 ScrollViewer 的子级时不会运行。
【问题讨论】:
标签: c# windows-phone-8 windows-phone storyboard