使用持续时间资源时的运行时异常

时间:2015-03-12 18:10:26

标签: windows-phone-8.1

我在 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>

但是,不幸的是,我在运行时遇到了一个不寻常的异常:

  

错误HRESULT E_FAIL已从调用COM组件返回。

我做错了什么?

0 个答案:

没有答案