[英]uwp dynamic storyboard target name
I have a Button
in inside a ListView.ItemTemplate
which mimicks the behavior of a dropdown button.我在
ListView.ItemTemplate
中有一个Button
,它模仿下拉按钮的行为。 And I want to give the button a rotation animation by using a StoryBoard
.我想通过使用 StoryBoard 给按钮旋转
StoryBoard
。
<Storyboard x:Name="FolderPathItemArrowAnimation">
<DoubleAnimation
By="90"
Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)"
Duration="0:0:0.25" />
</Storyboard>
<ListView
Background="AntiqueWhite"
HorizontalAlignment="Stretch"
ItemsSource="{x:Bind FolderChain, Mode=OneWay}"
ItemContainerStyle="{StaticResource StretchListViewItemStyle}"
Style="{StaticResource HorizontalListViewStyle}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="models:FolderTree">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Button
Style="{StaticResource FolderChainButtonStyle}"
Click="PathItemButton_Click" >
<Button.Content>
<TextBlock Text="{x:Bind Name}" />
</Button.Content>
</Button>
<Button
Name="{x:Bind Id, Converter={StaticResource FolderChainDropdownButtonNameConverter}}"
Grid.Column="1"
Width="30"
Click="PathItemDropDownButton_Click"
Style="{StaticResource FolderChainButtonStyle}"
Content=""
FontFamily="Segoe MDL2 Assets"
RenderTransformOrigin=".5,.5" >
<Button.RenderTransform>
<RotateTransform />
</Button.RenderTransform>
</Button>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Below is the code to start the animation. When running, I get an Exception says that Cannot resolve TargetName FolderChainItemDropdownButton1
.下面是启动 animation 的代码。运行时,我收到一个异常,提示
Cannot resolve TargetName FolderChainItemDropdownButton1
。 How can I use StoryBoard
on ListView.ItemTemplate
?如何在
ListView.ItemTemplate
上使用StoryBoard
?
private void PathItemDropDownButton_Click(object sender, RoutedEventArgs e)
{
Storyboard.SetTargetName(FolderPathItemArrowAnimation, (sender as FrameworkElement).Name);
FolderPathItemArrowAnimation.Begin();
}
get an Exception says that Cannot resolve TargetName FolderChainItemDropdownButton1
得到一个异常说 Cannot resolve TargetName FolderChainItemDropdownButton1
It looks SetTargetName
method can not get correct element where under DataTemplate.看起来
SetTargetName
方法无法在 DataTemplate 下获取正确的元素。 please try to use SetTarget
method to replace.请尝试使用
SetTarget
方法来替换。
Storyboard.SetTarget(FolderPathItemArrowAnimation, (sender as FrameworkElement));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.