internal void UpdateArgumentName(DesignTimeArgument argumentWrapper, string newName, string oldName)
        {
            ModelItemCollection argumentsCollection = this.GetArgumentCollection();

            //Since underlying object is an KeyedCollection, if we only update the property value, it won't update the key
            //Need to remove the object and add it again to update the key
            ModelItem argument = argumentWrapper.ReflectedObject;
            argumentsCollection.Remove(argument);
            argument.Properties[ArgumentNamePropertyName].SetValue(newName);
            argumentsCollection.Add(argument);
            this.ValidateArgumentName(argumentWrapper.GetArgumentName(), newName, oldName);

            //Update default value editor in Argument designer
            this.UpdateTypeDesigner(argumentWrapper);
        }
        void OnArgumentCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            //we need to track argument collection changes caused by undo/redo stack - 
            //in such case, we have to add/remove corresponding items from wrapper collection
            bool isUndoRedoInProgress = this.Context.Services.GetService<UndoEngine>().IsUndoRedoInProgress;
            if (isUndoRedoInProgress)
            {
                switch (e.Action)
                {
                    case NotifyCollectionChangedAction.Add:
                        foreach (ModelItem argument in e.NewItems)
                        {
                            var wrapper = this.argumentWrapperCollection
                                .FirstOrDefault(p => (ModelItem.Equals(p.ReflectedObject, argument)));

                            if (wrapper == null)
                            {
                                wrapper = new DesignTimeArgument(argument, this);
                                this.argumentWrapperCollection.Add(wrapper);
                            }
                        }
                        break;

                    case NotifyCollectionChangedAction.Remove:
                        foreach (ModelItem argument in e.OldItems)
                        {
                            var wrapper = this.argumentWrapperCollection.FirstOrDefault(p => ModelItem.Equals(p.ReflectedObject, argument));
                            if (null != wrapper)
                            {
                                this.argumentWrapperCollection.Remove(wrapper);
                            }
                        }
                        break;
                }
            }
        }
 internal void UpdateTypeDesigner(DesignTimeArgument argument)
 {
     this.dgHelper.UpdateDynamicContentColumns(argument);
 }
        public bool CreateNewArgumentWrapper()
        {
            bool result = false;

            if (null != this.ActivitySchema)
            {
                DynamicActivityProperty property = new DynamicActivityProperty()
                {
                    Name = this.GetDefaultName(),
                    Type = this.GetDefaultType(),
                };
                DesignTimeArgument wrapper = null;
                using (ModelEditingScope scope = this.ActivitySchema.BeginEdit((string)this.FindResource("addNewArgumentDescription")))
                {
                    ModelItem argument = this.GetArgumentCollection().Add(property);
                    wrapper = new DesignTimeArgument(argument, this);
                    this.argumentWrapperCollection.Add(wrapper);
                    scope.Complete();
                    result = true;
                }
                this.dgHelper.BeginRowEdit(wrapper);
            }
            return result;
        }