我发出错误"' ScaleTransform'在System.Windows.Controls.ListView'。"的名称范围内找不到名称。当ScaleTransform在另一个触发器中时,但是当我在Image.Triggers中设置它时,它工作正常吗?
<ListView.ItemTemplate>
<DataTemplate>
<DockPanel>
<TextBlock DockPanel.Dock="Bottom" Text="{Binding Name}"/>
<Image x:Name="Img" Source="{Binding Source}" Height="128" Width="128" Focusable="True">
<Image.RenderTransform>
<ScaleTransform x:Name="MyAnimatedScaleTransform" CenterX="25" CenterY="25" ScaleX="1" ScaleY="1" />
</Image.RenderTransform>
</Image>
</DockPanel>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.Triggers>
<EventTrigger RoutedEvent="ListView.SelectionChanged">
<BeginStoryboard Name="myBeginStoryboard">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="MyAnimatedScaleTransform" Storyboard.TargetProperty="(ScaleTransform.ScaleX)" To="1.5" Duration="0:0:0.25" AutoReverse="True" />
<DoubleAnimation Storyboard.TargetName="MyAnimatedScaleTransform" Storyboard.TargetProperty="(ScaleTransform.ScaleY)" To="1.5" Duration="0:0:0.25" AutoReverse="True"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ListView.Triggers>
</ListView>
我尝试了但也没有工作:
<ListView.ItemTemplate>
<DataTemplate>
<DockPanel>
<TextBlock DockPanel.Dock="Bottom" Text="{Binding Name}"/>
<Image x:Name="Img" Source="{Binding Source}" Height="128" Width="128" Focusable="True">
<Image.RenderTransform>
<ScaleTransform x:Name="MyAnimatedScaleTransform" CenterX="25" CenterY="25" ScaleX="1" ScaleY="1" />
</Image.RenderTransform>
</Image>
</DockPanel>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.Triggers>
<EventTrigger RoutedEvent="ListView.SelectionChanged">
<BeginStoryboard Name="myBeginStoryboard">
<Storyboard>
<DoubleAnimation Storyboard.Target="{Binding MyAnimatedScaleTransform}" Storyboard.TargetProperty="(ScaleTransform.ScaleX)" To="1.5" Duration="0:0:0.25" AutoReverse="True" />
<DoubleAnimation Storyboard.Target="{Binding MyAnimatedScaleTransform}" Storyboard.TargetProperty="(ScaleTransform.ScaleY)" To="1.5" Duration="0:0:0.25" AutoReverse="True"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ListView.Triggers>
</ListView>
答案 0 :(得分:0)
我发现DataTemplate中的控制器无法访问,因此我将我的cod Xaml更改为:
<ListView.ItemTemplate>
<DataTemplate>
<DockPanel>
<TextBlock DockPanel.Dock="Bottom" Text="{Binding Name}"/>
<Image x:Name="Img" Source="{Binding Source}" Height="128" Width="128" Focusable="True">
<Image.RenderTransform>
<ScaleTransform x:Name="MyAnimatedScaleTransform" CenterX="25" CenterY="25" ScaleX="1" ScaleY="1" />
</Image.RenderTransform>
<Image.Triggers>
<EventTrigger RoutedEvent="Image.MouseDown">
<BeginStoryboard Name="myBeginStoryboard">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="MyAnimatedScaleTransform" Storyboard.TargetProperty="(ScaleTransform.ScaleX)" To="1.5" Duration="0:0:0.25" AutoReverse="True" />
<DoubleAnimation Storyboard.TargetName="MyAnimatedScaleTransform" Storyboard.TargetProperty="(ScaleTransform.ScaleY)" To="1.5" Duration="0:0:0.25" AutoReverse="True"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Image.Triggers>
</Image>
</DockPanel>
</DataTemplate>
</ListView.ItemTemplate>
现在我已经回到了我的主要问题,当我在第一个动画结束(反向)之前第二次点击图像时,图像不会恢复到原始尺寸。