【发布时间】:2016-05-02 01:55:06
【问题描述】:
我在XAML 中有一个ListView 和一个ItemTemplate,每个项目都包含一个Button 和一个FontIcon。一旦按下按钮,我想在FontIcon 上做一个旋转动画。我已经在 DataTemplate 之外构建了它工作正常的行为,所以我将 Storyboard 添加到 ListView 中,现在我收到 Storyboard.TargetName 的错误。是否可以在DataTemplate 内的特定元素上执行DoubleAnimation,这是由DataTemplate 内的另一个元素触发的?
我之前在XAML 没有做过任何动画,所以如果我走错了路,请告诉我。
这是ListView 和Storyboard 的代码
<ListView x:Name="ItemList">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<StackPanel.Resources>
<Storyboard x:Name="TestStoryboard">
<DoubleAnimation
Duration="0:0:0.2"
To="180"
Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)"
Storyboard.TargetName="iconlist"
d:IsOptimized="True"/>
</Storyboard>
</StackPanel.Resources>
<Button Click="ButtonTest_Click">
<TextBlock Text="{Binding}" />
</Button>
<FontIcon x:Name="iconlist" Glyph="###" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
为了更好地理解这里是我正在构建的屏幕截图。我想通过单击ListView 的相应项目内的按钮来旋转表情符号:
【问题讨论】:
标签: c# xaml listview storyboard uwp