在 StoryBoard 上设置自定义附加属性
我有一个故事板,想要设置附加属性 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该可以解决问题。
请注意如何将名称添加到动画中,从目标属性名称中删除括号,然后使用 xaml 标头中的 xmlns 别名作为前缀。
在后面的代码中,您必须添加以下内容:
显然,最后一步是动画自定义附加属性所必需的。如果你问我的话,我真的很痛苦。
This should do the trick
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:
Apparently this last step is required for animating custom attached properties. A real pain if you'd ask me.
我遇到了这个:
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