我有一个故事板,想要设置附加属性 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));
这应该可以解决问题
<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));
显然,最后一步是动画自定义附加属性所必需的。如果你问我的话,我真的很痛苦。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)