在故事板设置自定义附加属性 [英] Set custom attached property on StoryBoard

查看:128
本文介绍了在故事板设置自定义附加属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个故事板,并想设置附加属性VisualStateUtility.InitialState。我已经试过各种组合,但物业从来没有得到解决。



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



如何设置的情节提要

 <我的自定义附加属性的值; ObjectAnimationUsingKeyFrames持续时间=0Storyboard.TargetProperty =(Fully.Qualified.Namespace.VisualStateUtility.InitialState)Storyboard.TargetName =ExpanderButton> 







 公共静态字符串GetInitialState(DependencyObject的OBJ)
{
回报(字符串)obj.GetValue(InitialStateProperty);
}

公共静态无效SetInitialState(OBJ的DependencyObject,字符串值)
{
obj.SetValue(InitialStateProperty,值);
}

//使用的DependencyProperty作为后备存储的初始化状态。这使得动画,造型,绑定等等...
公共静态只读的DependencyProperty InitialStateProperty =
DependencyProperty.RegisterAttached(初始化状态的typeof(串)的typeof(VisualStateUtility),新PropertyMetadata(NULL,OnInitialStatePropertyChanged ));


解决方案

这应该做的伎俩

 < ObjectAnimationUsingKeyFrames X:NAME =动画时间=0Storyboard.TargetProperty =xmlnsAlias​​:VisualStateUtility.InitialStateStoryboard.TargetName =ExpanderButton > 



公告的名称是如何加入到动画中,括号从目标属性名称,删除,这,然后与从XAML头中的xmlns前缀别名



在后面的代码你必须补充一点:

 的InitializeComponent(); 
Storyboard.SetTargetProperty(动画,新的PropertyPath(Fully.Qualified.Namespace.VisualStateUtility.InitialState));



显然,这最后一步是需要自定义动画附加属性。一个真正的痛苦,如果你问我。


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

解决方案

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.

这篇关于在故事板设置自定义附加属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆