void OnEditorClosing(object sender, EventArgs e)
        {
            if (this.expressionEditorInstance != null)
            {
                //these events are expected to be unregistered during lost focus event, but
                //we are unregistering them during unload just in case.  Ideally we want to
                //do this in the CloseExpressionEditor method
                this.expressionEditorInstance.LostAggregateFocus -= new EventHandler(OnEditorLostAggregateFocus);

                this.expressionEditorInstance.Closing -= new EventHandler(OnEditorClosing);
                this.expressionEditorInstance = null;
            }
            Border boarder = this.hostControl.Parent as Border;
            if (boarder != null)
            {
                boarder.Child = null;
            }
            this.hostControl = null;
            this.editorName = null;

        }
        void OnEditorLoaded(object sender, RoutedEventArgs e)
        {
            if (!this.isEditorLoaded)
            {
                // If the service exists, create an expression editor and add it to the grid - else switch to the textbox data template
                if (this.expressionEditorService != null)
                {
                    Border border = (Border)sender;
                    // Get the references and variables in scope
                    AssemblyContextControlItem assemblies = (AssemblyContextControlItem)this.Context.Items.GetValue(typeof(AssemblyContextControlItem));
                    List<ModelItem> declaredVariables = VisualBasicEditor.GetVariablesInScope(this.OwnerActivity);

                    ImportedNamespaceContextItem importedNamespaces = this.Context.Items.GetValue<ImportedNamespaceContextItem>();
                    importedNamespaces.EnsureInitialized(this.Context);
                    //if the expression text is empty and the expression type is set, then we initialize the text to prompt text
                    if (String.Equals(this.ExpressionText, string.Empty, StringComparison.OrdinalIgnoreCase) && this.ExpressionType != null)
                    {
                        this.Text = TypeToPromptTextConverter.GetPromptText(this.ExpressionType);
                    }

                    //this is a hack
                    this.blockWidth = Math.Max(this.ActualWidth - 8, 0);  //8 is the margin
                    if (this.HasErrors)
                    {
                        this.blockWidth = Math.Max(this.blockWidth - 16, 0); //give 16 for error icon
                    }
                    try
                    {
                        if (this.ExpressionType != null)
                        {
                            this.expressionEditorInstance = this.expressionEditorService.CreateExpressionEditor(assemblies, importedNamespaces, declaredVariables, this.Text, this.ExpressionType, new Size(this.blockWidth, this.blockHeight));
                        }
                        else
                        {
                            this.expressionEditorInstance = this.expressionEditorService.CreateExpressionEditor(assemblies, importedNamespaces, declaredVariables, this.Text, new Size(this.blockWidth, this.blockHeight));
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex.Message);
                    }

                    if (this.expressionEditorInstance != null)
                    {
                        try
                        {
                            this.expressionEditorInstance.VerticalScrollBarVisibility = this.VerticalScrollBarVisibility;
                            this.expressionEditorInstance.HorizontalScrollBarVisibility = this.HorizontalScrollBarVisibility;

                            this.expressionEditorInstance.AcceptsReturn = this.AcceptsReturn;
                            this.expressionEditorInstance.AcceptsTab = this.AcceptsTab;

                            // Add the expression editor to the text panel, at column 1
                            this.hostControl = this.expressionEditorInstance.HostControl;

                            // Subscribe to this event to change scrollbar visibility on the fly for auto, and to resize the hostable editor
                            // as necessary
                            this.expressionEditorInstance.LostAggregateFocus += new EventHandler(OnEditorLostAggregateFocus);
                            this.expressionEditorInstance.Closing += new EventHandler(OnEditorClosing);

                            // Set up Hostable Editor properties
                            this.expressionEditorInstance.MinLines = this.MinLines;
                            this.expressionEditorInstance.MaxLines = this.MaxLines;

                            this.expressionEditorInstance.HostControl.Style = (Style)FindResource("editorStyle");

                            border.Child = this.hostControl;
                            this.expressionEditorInstance.Focus();
                        }
                        catch (KeyNotFoundException ex)
                        {
                            Debug.Fail("Unable to find editor with the following editor name: " + this.editorName, ex.Message);
                        }
                    }
                }

                if (this.expressionEditorInstance == null)
                {
                    this.ContentTemplate = (DataTemplate)FindResource("textbox");
                }
                this.PerfProvider.WorkflowDesignerExpressionEditorLoaded();

                this.isEditorLoaded = true;
            }
        }