我想多次使用DoubleAnimation。下面的代码是:
<Window x:Class="Project.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Window.Resources>
<DoubleAnimation x:Key="LeftAnimation" Storyboard.TargetProperty="(Canvas.Left)" From="0" To="100" />
<DoubleAnimation x:Key="TopAnimation" Storyboard.TargetProperty="(Canvas.Top)" From="0" To="100" />
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<BeginStoryboard>
<Storyboard Storyboard.TargetName="AnimatedBorder1">
<StaticResourceExtension ResourceKey="LeftAnimation" />
</Storyboard>
</BeginStoryboard>
<BeginStoryboard>
<Storyboard Storyboard.TargetName="AnimatedBorder2">
<StaticResourceExtension ResourceKey="LeftAnimation" />
<StaticResourceExtension ResourceKey="TopAnimation" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>
<Canvas>
<Border x:Name="AnimatedBorder1" Background="Blue" Width="20" Height="20" />
<Border x:Name="AnimatedBorder2" Background="Red" Width="20" Height="20" />
</Canvas>
</Window>
代码工作正常,但ReSharper在<StaticResourceExtension ResourceKey="LeftAnimation" />
行下划线LeftAnimation并说:"无效的资源类型:预期类型是'TriggerCollection',实际类型是'DoubleAnimation'."
这真的是一个问题还是ReSharper(9.2版)的一个bug ?
编辑后的解决方案:
-
资源:
<Window.Resources> <TimelineCollection x:Key="TimelinesCollectionKey1"> <DoubleAnimation Storyboard.TargetProperty="(Canvas.Left)" From="0" To="100" /> </TimelineCollection> <TimelineCollection x:Key="TimelinesCollectionKey2"> <DoubleAnimation Storyboard.TargetProperty="(Canvas.Top)" From="0" To="100" /> </TimelineCollection></Window.Resources>
触发: <Window.Triggers> <EventTrigger RoutedEvent="Window.Loaded"> <BeginStoryboard> <Storyboard Storyboard.TargetName="AnimatedBorder1"> <!--<StaticResourceExtension ResourceKey="LeftAnimation" />--> <Storyboard.Children> <ParallelTimeline Children="{StaticResource TimelinesCollectionKey1}"></ParallelTimeline> </Storyboard.Children> </Storyboard> </BeginStoryboard> <BeginStoryboard> <Storyboard Storyboard.TargetName="AnimatedBorder2"> <Storyboard.Children> <ParallelTimeline Children="{StaticResource TimelinesCollectionKey1}"></ParallelTimeline> <ParallelTimeline Children="{StaticResource TimelinesCollectionKey2}"></ParallelTimeline> </Storyboard.Children> </Storyboard> </BeginStoryboard> </EventTrigger></Window.Triggers>
目标:
<Canvas> <Border x:Name="AnimatedBorder1" Background="Blue" Width="20" Height="20" /> <Border x:Name="AnimatedBorder2" Background="Red" Width="20" Height="20" /></Canvas>
认为,