locked
WF4 Rehosted Designer Custom Expression Issues...... RRS feed

  • Question

  • Hi, 

    As we don't have the intelligence support in WF4 rehosted designer itself, we wanted to provide the custom window to build the expressions. To open the custom window we have used IExpressionEditorService, IExpressionEditorInstance…

    Code to open Custom Expression window.....

    public class CustomExpressionEditorInstance : IExpressionEditorInstance

    {

     

    TextBox txtExpressionTextBox = new TextBox();

    public CustomExpressionEditorInstance()

    {

    txtExpressionTextBox.MouseDoubleClick += new MouseButtonEventHandler(txtExpressionTextBox_MouseDoubleClick);

    }

     

    void txtExpressionTextBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)

    {

    //Opening the Custom expression window

    }

     

    - - - - - - - - - - - - - - - - - - - - -

    - - - - - - - - - - - - - - - - - - - - -

    }

    Issue #1: When I drag the Assign activity to designer and double click on the To expression textbox(To),  I am able to open the custom expression window.  Here my issue is how can we get the active(selected) property(In this case To). In custom expression window.

    Issue #2:  When I double click on the PropertyInspector  expression textbox property(To), I am able to open the Custom expression textbox.  But how to find the event source either this event is firing from PropertyInspector  or Designer..

    Issue #3: After adding the new variables to rehosted designer,  If I open custom expression window I am not getting the updated variables…

    public IExpressionEditorInstance CreateExpressionEditor(AssemblyContextControlItem assemblies, ImportedNamespaceContextItem importedNamespaces, List<ModelItem> variables, string text, Type expressionType, System.Windows.Size initialSize)

    { - - - - - - - - }

    please help us to resolve these issues....


    Hanumantha Rao
    Friday, December 17, 2010 11:30 AM

Answers

  • So http://blogs.msdn.com/b/cathyk/archive/2009/11/05/implementing-a-custom-expression-editor.aspx does not solve your problem.

    let me try to understand your issues:

    Issue #1: When I drag the Assign activity to designer and double click on the To expression textbox(To), I am able to open the custom expression window. Here my issue is how can we get the active(selected) property(In this case To). In custom expression window.

    what do you mean " how can we get the active property in custom expressin window"? I guess you are using a ComboBox to simulate the intellisense, and at the same time, you should have a textbox to enter the value, is that right?

    then you should have 2 handler:

    comboBox.SelectionChanged +=

     

    new SelectionChangedEventHandler(comboBox_SelectionChanged);

    txtBox.PreviewKeyDown +=

     

    new System.Windows.Input.KeyEventHandler(txtBox_PreviewKeyDown);

    Issue #3: After adding the new variables to rehosted designer, If I open custom expression window I am not getting the updated variables…

    you can create the Constructor like this:

    public CustomExpressionEditorInstance(List<ModelItem> variables)

    And in the constructor, read the passed in variables in a Dictionary,which you can read later

    and your create method should be something like:

    public

     

     

    IExpressionEditorInstance CreateExpressionEditor(AssemblyContextControlItem assemblies, ImportedNamespaceContextItem importedNamespaces, List<ModelItem> variables, string text)

    {

     

     

    CustomExpressionEditorInstance instance = new CustomExpressionEditorInstance(variables);

     

     

    return instance;

    }

    • Marked as answer by zhenyu dai Thursday, March 10, 2011 3:42 AM
    Thursday, March 3, 2011 7:24 AM

All replies

    • Marked as answer by Andrew_Zhu Monday, December 27, 2010 2:50 AM
    • Unmarked as answer by MeetHanu Monday, December 27, 2010 6:35 AM
    Tuesday, December 21, 2010 7:34 AM
  • here is the sample code of how to implement a custom expression editor:

    http://blogs.msdn.com/b/cathyk/archive/2009/11/05/implementing-a-custom-expression-editor.aspx

    • Marked as answer by Andrew_Zhu Monday, January 10, 2011 7:33 AM
    • Unmarked as answer by MeetHanu Tuesday, January 11, 2011 10:49 AM
    Sunday, January 9, 2011 9:48 AM
  • So http://blogs.msdn.com/b/cathyk/archive/2009/11/05/implementing-a-custom-expression-editor.aspx does not solve your problem.

    let me try to understand your issues:

    Issue #1: When I drag the Assign activity to designer and double click on the To expression textbox(To), I am able to open the custom expression window. Here my issue is how can we get the active(selected) property(In this case To). In custom expression window.

    what do you mean " how can we get the active property in custom expressin window"? I guess you are using a ComboBox to simulate the intellisense, and at the same time, you should have a textbox to enter the value, is that right?

    then you should have 2 handler:

    comboBox.SelectionChanged +=

     

    new SelectionChangedEventHandler(comboBox_SelectionChanged);

    txtBox.PreviewKeyDown +=

     

    new System.Windows.Input.KeyEventHandler(txtBox_PreviewKeyDown);

    Issue #3: After adding the new variables to rehosted designer, If I open custom expression window I am not getting the updated variables…

    you can create the Constructor like this:

    public CustomExpressionEditorInstance(List<ModelItem> variables)

    And in the constructor, read the passed in variables in a Dictionary,which you can read later

    and your create method should be something like:

    public

     

     

    IExpressionEditorInstance CreateExpressionEditor(AssemblyContextControlItem assemblies, ImportedNamespaceContextItem importedNamespaces, List<ModelItem> variables, string text)

    {

     

     

    CustomExpressionEditorInstance instance = new CustomExpressionEditorInstance(variables);

     

     

    return instance;

    }

    • Marked as answer by zhenyu dai Thursday, March 10, 2011 3:42 AM
    Thursday, March 3, 2011 7:24 AM
  • Hi EVuri,

    It seems like you are building this custom window because there is no intellisense for VB expression in rehost. Could you help me understand who the target customers are for your rehost WF designer? Are they developers who know how to write VB or more like information workers who don't know anything about coding?

    I'm asking because if you are targeting developers, than intellisense is more like a productivity tool for them. It's important from a developer perspective.

    But if you are targeting information workers, then do you think even with intellisense, they will be happy of using VB? If there are options, would you rather provide them VB + intellisense or some other custom expression editing experience which is more proper for them?

     

    My email address is Guang.Yang@microsoft.com. Looking forward to see your reply here or through email. Thanks.

    Thursday, April 14, 2011 7:50 AM
  • Hi EVuri,

    It seems like you are building this custom window because there is no intellisense for VB expression in rehost. Could you help me understand who the target customers are for your rehost WF designer? Are they developers who know how to write VB or more like information workers who don't know anything about coding?

    I'm asking because if you are targeting developers, than intellisense is more like a productivity tool for them. It's important from a developer perspective.

    But if you are targeting information workers, then do you think even with intellisense, they will be happy of using VB? If there are options, would you rather provide them VB + intellisense or some other custom expression editing experience which is more proper for them?

     

    My email address is Guang.Yang@microsoft.com. Looking forward to see your reply here or through email. Thanks.


    We have several large customers who will have no problems to have somebody learn VB to be able to make their own workflows. 

    As our developers also work with the rehosted designer missing intellisense is very irritating.

    Wednesday, May 18, 2011 3:17 PM
  • Hi Guang,

    I want to get the selected expression in a custom ActivityDesigner. I'm implementing IExpressionEditorService and can get the text from IExpressionEditorInstance CreateExpressionEditor(), but also want to get the expression ModelItem. My WF designer code can get the selected ActivityDesinger as

    Selection sel = wd.Context.Items.GetValue<Selection>();

    ModelItem mi = (ModelItem)sel.PrimarySelection;

    As expected, I get the ActivityDesigner ModelItem. What I want is the selected Expression ModelItem. When I inspect the ContextItem list in ad.Context.Items within VS.NET, I can see there is a System.Activities.Presentation.ExpressionSelection class containing the selected expression ModelItem. This is exactly what I need; however, System.Activities.Presentation does not contain a public ExpressionSelection type. How do I get the ExpressionSelection?

    The scenario is a WF Designer for a Power User. I want to implement custom expression builders that are available when a user selects a custom Expression Editor user control. Therefore, in addition to the expression text from IExpressionEditorInstance CreateExpressionEditor(), I need the expression ModelItem so I have expression context. I can get the results I want by setting an Activity Designer Tag in the ExpressionTextBox_GotFocus event handler, but, this is not very elegant.

     

     

     

    • Proposed as answer by dvana Friday, August 12, 2011 2:56 PM
    • Unproposed as answer by dvana Friday, August 12, 2011 2:56 PM
    Thursday, August 11, 2011 3:01 PM
  • I developed one way to get an ActivityDesigner's selected expression from the WF designer. I don’t like the code behind, but it works. Raise a GotFocus event from the ActivityDesigner passing the ExpressionTextBox  then handle the event in the workflow designer. The DesignerView_GotFocus gets a reference  to the selected ActivityDesigner. Then handle the ActivityDesigner.GotFocus event raised from the ActivityDesigner.

    From an Activity Designer:

    <sapv:ExpressionTextBox

    GotFocus="ExpressionTextBox_GotFocus"/>

     

    Code Behind

    private void ExpressionTextBox_GotFocus(object sender, RoutedEventArgs e)

    {

    RaiseEvent(new RoutedEventArgs(System.Activities.Presentation.ActivityDesigner.GotFocusEvent, (sender as ExpressionTextBox)));

    }

     

    From Workflow Designer:

    void designerView_GotFocus(object sender, RoutedEventArgs e)

    {

            Selection sel = wd.Context.Items.GetValue<Selection>();

     

            if (sel != null)

            {

                ActivityDesigner ad = (ActivityDesigner)sel.PrimarySelection.View;

                ad.GotFocus += new RoutedEventHandler(ad_GotFocus);

            }

    }

     

    void ad_GotFocus(object sender, RoutedEventArgs e)

        {

          ExpressionTextBox etb = (e.OriginalSource as ExpressionTextBox);

          if (etb != null)

          {

            if (this.expressionEditorService.instance != null)

    this.expressionEditorService.instance.Expression = etb.SelectedPath();

     

     

          }

        }

     

    public static class ExpressionTextBoxExitensions

      {

        public static string SelectedPath(this ExpressionTextBox etb)

        {

          return etb.GetBindingExpression(ExpressionTextBox.ExpressionProperty).ParentBinding.Path.Path;

        }

      }

    • Proposed as answer by dvana Friday, August 12, 2011 2:58 PM
    Friday, August 12, 2011 2:57 PM