Set custom attached property on StoryBoard

前端 未结 2 665
既然无缘
既然无缘 2021-01-13 18:21

I have a storyboard and would like to set the attached property VisualStateUtility.InitialState. I\'ve tried various combinations, but the property never gets resolved.

相关标签:
2条回答
  • 2021-01-13 19:00

    I ran into this:

    http://forums.silverlight.net/t/182227.aspx

    Which another user says it's un-supported.

    Frank Lan Writes:

    Hi, It's a known issue. And the workaround seems to be: animate the custom attached property from code instead of xaml. Sorry for any inconvenience caused by the issue. Frank Lan Microsoft Online Community Support

    0 讨论(0)
  • 2021-01-13 19:13

    This should do the trick

    <ObjectAnimationUsingKeyFrames x:Name="animation" Duration="0" Storyboard.TargetProperty="xmlnsAlias:VisualStateUtility.InitialState"  Storyboard.TargetName="ExpanderButton">
    

    Notice how a name is added to the animation, the parentheses are removed from the target property name, which is then prefixed with the xmlns alias from the xaml header.

    In your code behind you'll have to add this:

    InitializeComponent();
    Storyboard.SetTargetProperty(animation, new PropertyPath(Fully.Qualified.Namespace.VisualStateUtility.InitialState));
    

    Apparently this last step is required for animating custom attached properties. A real pain if you'd ask me.

    0 讨论(0)
提交回复
热议问题