【问题标题】:Set custom attached property on StoryBoard在 StoryBoard 上设置自定义附加属性
【发布时间】:2011-11-23 03:47:04
【问题描述】:

我有一个情节提要并想设置附加属性 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));

【问题讨论】:

  • 你能提供你的附属财产的声明吗?您不会通过 TargetProperty 中的完全限定名称来引用它,因为点仅表示子成员,而不是命名空间。只是简短的版本“InitialState”。
  • ...当您确实添加了 12 小时前所做的更改时,请确保添加后续评论,以便我们真正注意到 :)
  • +1 用于提供代码。更容易看出哪里出了问题:)

标签: c# silverlight storyboard visualstatemanager


【解决方案1】:

这应该可以解决问题

<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));

显然,为自定义附加属性设置动画需要最后一步。如果你问我,真的很痛苦。

【讨论】:

    【解决方案2】:

    我遇到了这个:

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

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

    Frank Lan 写道:

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

    【讨论】:

    • 我不认为这是正确的。我确定我之前有动画附加属性......很奇怪......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-05
    • 1970-01-01
    • 2017-03-06
    • 1970-01-01
    • 2021-07-21
    • 2011-08-26
    相关资源
    最近更新 更多