在 StoryBoard 上设置自定义附加属性

发布于 2024-12-06 02:03:46 字数 1087 浏览 6 评论 0原文

我有一个故事板,想要设置附加属性 VisualStateUtility.InitialState。我尝试过各种组合,但属性从未得到解决。

我收到以下错误:无法解析 TargetProperty (VisualStateUtility.InitialState)

如何在 Storyboard 上设置自定义附加属性的值?

<ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="(Fully.Qualified.Namespace.VisualStateUtility.InitialState)"  Storyboard.TargetName="ExpanderButton">

    public static string GetInitialState(DependencyObject obj)
    {
        return (string)obj.GetValue(InitialStateProperty);
    }

    public static void SetInitialState(DependencyObject obj, string value)
    {
        obj.SetValue(InitialStateProperty, value);
    }

    // Using a DependencyProperty as the backing store for InitialState.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty InitialStateProperty =
        DependencyProperty.RegisterAttached("InitialState", typeof(string), typeof(VisualStateUtility), new PropertyMetadata(null,OnInitialStatePropertyChanged));

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.

I get the following error: Cannot resolve TargetProperty (VisualStateUtility.InitialState)

How can I set the value of my custom attached property on the Storyboard?

<ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="(Fully.Qualified.Namespace.VisualStateUtility.InitialState)"  Storyboard.TargetName="ExpanderButton">

    public static string GetInitialState(DependencyObject obj)
    {
        return (string)obj.GetValue(InitialStateProperty);
    }

    public static void SetInitialState(DependencyObject obj, string value)
    {
        obj.SetValue(InitialStateProperty, value);
    }

    // Using a DependencyProperty as the backing store for InitialState.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty InitialStateProperty =
        DependencyProperty.RegisterAttached("InitialState", typeof(string), typeof(VisualStateUtility), new PropertyMetadata(null,OnInitialStatePropertyChanged));

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谈场末日恋爱 2024-12-13 02:03:46

这应该可以解决问题。

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

请注意如何将名称添加到动画中,从目标属性名称中删除括号,然后使用 xaml 标头中的 xmlns 别名作为前缀。

在后面的代码中,您必须添加以下内容:

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

显然,最后一步是动画自定义附加属性所必需的。如果你问我的话,我真的很痛苦。

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.

雪花飘飘的天空 2024-12-13 02:03:46

我遇到了这个:

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

另一位用户说它不受支持。

弗兰克·兰 (Frank Lan) 写道:

嗨,
这是一个已知问题。解决方法似乎是:通过代码而不是 xaml 对自定义附加属性进行动画处理。
对于该问题造成的任何不便,我们深表歉意。
弗兰克·兰
Microsoft 在线社区支持

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文