有人可以告诉我如何向intellisense提供的自定义活动中添加变量吗? [英] Can somebody please tell me how to add a variable to a custom activity that is available from intellisense?

查看:49
本文介绍了有人可以告诉我如何向intellisense提供的自定义活动中添加变量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来吧,这很容易回答.到目前为止,我尝试过的任何事情都不会使设计师踩到床.

Come on, this has GOT to be easy to answer.  So far, nothing I try works without causing the designer to s*t the bed.


推荐答案

XAML序列化/反序列化有趣地结合了将构造函数添加到公共Collection中的构造函数.真的希望变量是一个动态集合,您可以在其中添加/删除项,并且默认情况下也将其填充为文本",还是只希望名称"text"在您的子活动范围之内?

如果我不确定您是否需要变量集合,也许您可​​以使用CacheMetadata注册"变量(但我还没有尝试过).

如果前者,您可以使用ISupportInitialize解决问题,以便可以显式处理XAML反序列化情况-这似乎对我有用:

XAML serialization/deserialization combines interestingly with constructors that add something to a public Collection.

Do you really want Variables to be a dynamic collection, where you can add/delete items and also populated with 'text' by default, or do you just want the name 'text' to be in scope for your child activity?

If the latter I'm not sure you need a Variables collection, maybe you can just 'register' the variable using CacheMetadata (but I haven't tried this out yet).

If the former, you might solve the problem by using ISupportInitialize, so that you can explicitly handle the XAML deserialization case - this seemed to work for me:

 

ContentProperty ("Child" )]

    [ContentProperty("Child")]

公共 密封 class HurrDurr : NativeActivity ISupportInitialize

    public sealed class HurrDurr : NativeActivity, ISupportInitialize

    {

私有 变量< 字符串> ;文字{获取; 设置; }

        private Variable<string> Text { get; set; }

公共 活动子级{ get ; 设置; }

        public Activity Child { get; set; }

公共 收藏< 变量 >变量{获取; 设置; }

        public Collection<Variable> Variables { get; set; }

公共 HurrDurr()

        public HurrDurr()

        {

变量< 字符串>(文本" );

            Text = new Variable<string>("text");

收藏< 变量>(){文字};

            Variables = new Collection<Variable>() { Text };

        }

受保护的 覆盖 void 执行( NativeActivityContext 上下文)

        protected override void Execute(NativeActivityContext context)

        {

            context.ScheduleActivity(Child);

        }

无效 ISupportInitialize .BeginInit()

        void ISupportInitialize.BeginInit()

        {

//如果这被调用,我们不仅会被构造,还会被初始化-

            //If this is called, we aren't just getting constructed, but we're getting initialized -

//(有些东西会尝试设置我们的所有属性.)

            //(Something is going to try to set all our properties.)

收藏< 变量>();

            Variables = new Collection<Variable>();

        }

无效 ISupportInitialize .EndInit()

        void ISupportInitialize.EndInit()

        {

        }

    }

Tim


这篇关于有人可以告诉我如何向intellisense提供的自定义活动中添加变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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