void OnVariableCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            var isUndoRedoInProgress = this.Context.Services.GetService<UndoEngine>().IsUndoRedoInProgress;

            switch (e.Action)
            {
                case NotifyCollectionChangedAction.Add:
                    foreach (ModelItem variable in e.NewItems)
                    {
                        DesignTimeVariable wrapper = this.variableWrapperCollection
                            .FirstOrDefault<DesignTimeVariable>(p => (ModelItem.Equals(p.ReflectedObject, variable)));

                        if (wrapper == null)
                        {
                            wrapper = new DesignTimeVariable(variable, this);
                            this.variableWrapperCollection.Add(wrapper);
                        }
                        if (null != this.variableToSelect && this.variableToSelect == variable)
                        {
                            this.variableDataGrid.SelectedItem = wrapper;
                            this.variableToSelect = null;

                            int index = this.variableDataGrid.Items.IndexOf(this.variableDataGrid.SelectedItem);
                            DataGridRow row = DataGridHelper.GetRow(this.variableDataGrid, index);
                            if (!row.IsSelected)
                            {
                                row.IsSelected = true;
                            }

                            if (this.continueScopeEdit)
                            {
                                DataGridCell cell = DataGridHelper.GetCell(this.variableDataGrid, index, 2);
                                cell.IsEditing = true;
                            }
                        }
                    }
                    break;

                case NotifyCollectionChangedAction.Remove:
                    foreach (ModelItem variable in e.OldItems)
                    {
                        DesignTimeVariable wrapper = this.variableWrapperCollection.FirstOrDefault(p => ModelItem.Equals(p.ReflectedObject, variable));
                        if (null != wrapper)
                        {
                            //in case of undo/redo operation - just remove old reference to the wrapper, new one will be added be undo stack anyway
                            if (!this.ScopesList.Contains((sender as ModelItem).Parent) || isUndoRedoInProgress)
                            {
                                this.variableWrapperCollection.Remove(wrapper);
                            }
                        }
                    }
                    break;
            }
            this.RaiseEvent(new RoutedEventArgs(VariableDesigner.VariableCollectionChangedEvent, this));
        }
 internal void UpdateTypeDesigner(DesignTimeVariable variable)
 {
     this.dgHelper.UpdateDynamicContentColumns(variable);
 }
        internal void ChangeVariableType(DesignTimeVariable oldVariableWrapper, Variable newVariable)
        {
            //check who is the sender of the event - data grid or property inspector
            int index = this.variableDataGrid.Items.IndexOf(this.variableDataGrid.SelectedItem);
            DataGridCell cell = DataGridHelper.GetCell(this.variableDataGrid, index, 1);
            bool shouldReselct = cell.IsEditing;

            //get location of the variable
            ModelItemCollection container = VariableHelper.GetVariableCollection(oldVariableWrapper.ReflectedObject.Parent.Parent);
            index = container.IndexOf(oldVariableWrapper.ReflectedObject);
            //remove all value 
            container.RemoveAt(index);
            oldVariableWrapper.Dispose();
            oldVariableWrapper.Initialize(container.Insert(index, newVariable));
        }
 internal void NotifyVariableScopeChanged(DesignTimeVariable variable)
 {
     this.variableToSelect = null != variable ? variable.ReflectedObject : null;
     int index = this.variableDataGrid.Items.IndexOf(this.variableDataGrid.SelectedItem);
     DataGridCell cell = DataGridHelper.GetCell(this.variableDataGrid, index, 2);
     this.continueScopeEdit = cell.IsEditing;
 }
 public bool CreateNewVariableWrapper()
 {
     bool result = false;
     ModelItemCollection scope = this.GetDefaultVariableScope();
     if (null != scope)
     {
         DesignTimeVariable wrapperObject = null;
         Variable variable = Variable.Create(this.GetDefaultName(), this.GetDefaultType(), VariableModifiers.None);
         using (ModelEditingScope change = scope.BeginEdit((string)this.FindResource("addNewVariableDescription")))
         {
             ModelItem wrappedVariable = scope.Add(variable);
             wrapperObject = new DesignTimeVariable(wrappedVariable, this);
             this.variableWrapperCollection.Add(wrapperObject);
             change.Complete();
             result = true;
         }
         this.dgHelper.BeginRowEdit(wrapperObject);
     }
     return result;
 }