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

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

                    //this is a hack
                    BlockWidth = Math.Max(ActualWidth - 8, 0);  //8 is the margin
                    if (HasErrors)
                    {
                        BlockWidth = Math.Max(BlockWidth - 16, 0); //give 16 for error icon
                    }
                    try
                    {
                        if (ExpressionType != null)
                        {
                            ExpressionEditorInstance = ExpressionEditorService1.CreateExpressionEditor(assemblies, importedNamespaces, declaredVariables, Text, ExpressionType, new Size(BlockWidth, BlockHeight));
                        }
                        else
                        {
                            ExpressionEditorInstance = ExpressionEditorService1.CreateExpressionEditor(assemblies, importedNamespaces, declaredVariables, Text, new Size(BlockWidth, BlockHeight));
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }

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

                            ExpressionEditorInstance.AcceptsReturn = AcceptsReturn;
                            ExpressionEditorInstance.AcceptsTab    = AcceptsTab;

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

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

                            // Set up Hostable Editor properties
                            ExpressionEditorInstance.MinLines = MinLines;
                            ExpressionEditorInstance.MaxLines = MaxLines;

                            ExpressionEditorInstance.HostControl.Style = (Style)FindResource("editorStyle");

                            border.Child = HostControl;
                            ExpressionEditorInstance.Focus();
                        }
                        catch (KeyNotFoundException ex)
                        {
                            new ApplicationException("Unable to find editor with the following editor name: " + EditorName);
                        }
                    }
                }
                IsEditorLoaded = true;
            }
        }
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     return(TypeToPromptTextConverter.GetPromptText(value));
 }