尝试在XAML故事板动画中使用用户控件的自定义属性会引发无法解决TargetProperty错误

时间:2019-03-17 09:54:40

标签: c# xaml user-controls storyboard

我正在尝试将我的用户控件MyControl包含在情节提要动画中,并为该控件的自定义属性MyProperty设置动画。故事板包含在另一个用户控件中。

但是,使用下面的代码,Visual Studio Blend 2017在情节提要的设计视图中引发以下错误:

异常:未检测到已安装的组件。 无法解析指定对象上的TargetProperty MyProperty。

问题似乎出在custom属性上,因为用Width之类的东西代替它可以很好地工作。另外,包含EnableDependentAnimation="True"不能解决问题。

XAML:

<UserControl.Resources>
    <Storyboard x:Name="MyStoryboard">

        <DoubleAnimationUsingKeyFrames
            EnableDependentAnimation="True"
            Storyboard.TargetName="myControl"
            Storyboard.TargetProperty="MyProperty"
        >
            <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
            <EasingDoubleKeyFrame KeyTime="0:0:2.0" Value="100"/>
        </DoubleAnimationUsingKeyFrames>

    </Storyboard>
</UserControl.Resources>

<Grid>
    <local:MyControl x:Name="myControl" Width="22" Height="22" MyProperty="0" />
</Grid>

我正在为UWP(Windows 10)用户控件的属性设置动画,键入double:

public sealed partial class My Control : UserControl

public double MyProperty
{
    get
    {
        return myProperty;
    }
    set
    {
        myProperty = value;
        Redraw();
    }
}

0 个答案:

没有答案