Windows phone 8.1 使用持续时间资源时出现运行时异常

Windows phone 8.1 使用持续时间资源时出现运行时异常,windows-phone-8.1,Windows Phone 8.1,我正在Windows Phone 8.1(WinRT)上实现一个自定义控件。其模板中的所有动画元素都具有相同的动画持续时间。所以我试着把它转移到资源上。以下是一段代码片段: <ControlTemplate TargetType="local:ExampleControl"> <Grid Background="{TemplateBinding Background}"> <Grid.RowDefinitions>

我正在Windows Phone 8.1(WinRT)上实现一个自定义控件。其模板中的所有动画元素都具有相同的动画持续时间。所以我试着把它转移到资源上。以下是一段代码片段:

<ControlTemplate TargetType="local:ExampleControl">
    <Grid Background="{TemplateBinding Background}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Grid.Resources>
            <Duration x:Key="AnimationDuration">0:0:0.2</Duration>
        </Grid.Resources>

        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="ExampleControlStateGroup">
                <VisualStateGroup.Transitions>
                    <VisualTransition GeneratedDuration="0:0:0.2">
                        <VisualTransition.GeneratedEasingFunction>
                            <CubicEase EasingMode="EaseInOut" />
                        </VisualTransition.GeneratedEasingFunction>
                    </VisualTransition>
                </VisualStateGroup.Transitions>
                <VisualState x:Name="ExampleControlClosedState">
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="ShadowFragment"
                                         Storyboard.TargetProperty="Opacity"
                                         To="0"
                                         Duration="{StaticResource AnimationDuration}" />
                        // other animations here
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="ExampleControlOpenedState">
                    <Storyboard>
                        // some animations here 
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <Grid Grid.Row="0"
              // some content here
        </Grid>
    </Grid>
</ControlTemplate>

0:0:0.2
//其他动画在这里
//这里有一些动画

可以吗您已经用一个键定义了持续时间
AnimationDuration
,并使用了
StaticResource-SideBarAnimationDuration
。可能是复制粘贴错误。当你删除上面的代码时,错误消失了吗?对不起,这实际上是在写问题时的一个复制粘贴错误。所以问题仍然存在。我不能将持续时间用作资源。你能说明你在哪里定义这个双重动画吗?我在示例中添加了更多的代码。也许这有助于发现问题。