0

我想多次使用 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将 LeftAnimation下划线并<StaticResourceExtension ResourceKey="LeftAnimation" />说:“无效的资源类型:预期类型是 'TriggerCollection',实际类型是 'DoubleAnimation'。

这真的是一个问题还是 ReSharper(9.2 版)中的一个错误?

4

1 回答 1

1

这是一个编辑的解决方案:

  1. 资源:

    <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>
    
  2. 触发器:

    <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>
    
  3. 目标:

    <Canvas>
    <Border x:Name="AnimatedBorder1" Background="Blue" Width="20" Height="20" />
    <Border x:Name="AnimatedBorder2" Background="Red" Width="20" Height="20" /></Canvas>
    

问候,

于 2015-10-18T07:36:21.773 回答