locked
Activity designer - access expression on designer canvas RRS feed

  • Question

  • Hi All

    I'm interested in redesigning the Flow switch activity so that the expression string which is normally in the properties is actually on the activity (canvas) itself. My BingFu is letting me down today, as I have not been able to determine how to do this, so if any one has examples OR links I would be greatful.

    My assumption was that I would be binding a ModelItem or ExpressionTextBox?

    Cheers
    J.

    Monday, February 1, 2010 7:53 PM

Answers

  • if you just want to display the expression string on the flowswitch designer, you can use following code  here I load the flowswitch directly, so it's the root, for your code, you need to get the modelitem of flowswitch first

    ModelItem item = designer.Context.Services.GetService<ModelService>().Root;
                WorkflowViewElement element = item.View as WorkflowViewElement;
                if (element.Content != null)
                {
                    Label lab = new Label();
                    lab.Content = item.Properties["Expression"].ComputedValue.ToString();
                    Grid grid = element.Content as Grid;
                    grid.Children.Add(lab);
                   
                   
                }
            }


    and you need to bind the modelproperty change event for item.Properties["Expression"] to update the value on the label on flowswitch designer

    if you also want to edit the expression value on flowswitch designer, you can use Expressiontextbox instead.
    and you need to bind the LostFocut event, if you modify the text on the textbox, please update the value of item.Properties["Expression"].

    • Proposed as answer by Ye Yu - MSFT Monday, February 1, 2010 8:34 PM
    • Marked as answer by Special_Jimmy Tuesday, February 2, 2010 1:33 AM
    Monday, February 1, 2010 8:34 PM
  • that's not easy to do the same from xaml.
    unless you rewrite the whole flowswitchDesigner class, and bind the flowSwitchActvity to your own created designer.
    • Proposed as answer by Ye Yu - MSFT Tuesday, February 2, 2010 1:19 AM
    • Marked as answer by Special_Jimmy Tuesday, February 2, 2010 1:33 AM
    Tuesday, February 2, 2010 1:19 AM

All replies

  • do you mean you want to add the expression string on the flowswitch designer directly?

    Monday, February 1, 2010 7:56 PM
  • Yes I believe so! :)
    Monday, February 1, 2010 8:08 PM
  • if you just want to display the expression string on the flowswitch designer, you can use following code  here I load the flowswitch directly, so it's the root, for your code, you need to get the modelitem of flowswitch first

    ModelItem item = designer.Context.Services.GetService<ModelService>().Root;
                WorkflowViewElement element = item.View as WorkflowViewElement;
                if (element.Content != null)
                {
                    Label lab = new Label();
                    lab.Content = item.Properties["Expression"].ComputedValue.ToString();
                    Grid grid = element.Content as Grid;
                    grid.Children.Add(lab);
                   
                   
                }
            }


    and you need to bind the modelproperty change event for item.Properties["Expression"] to update the value on the label on flowswitch designer

    if you also want to edit the expression value on flowswitch designer, you can use Expressiontextbox instead.
    and you need to bind the LostFocut event, if you modify the text on the textbox, please update the value of item.Properties["Expression"].

    • Proposed as answer by Ye Yu - MSFT Monday, February 1, 2010 8:34 PM
    • Marked as answer by Special_Jimmy Tuesday, February 2, 2010 1:33 AM
    Monday, February 1, 2010 8:34 PM
  • Is there an option for doing the same from the xaml, similar to this:


    <sapv:ExpressionTextBox 
                  HintText="Add switch expression"
                  Expression="{Binding Path=ModelItem.Expression, Mode=TwoWay}"
                  OwnerActivity="{Binding Path=ModelItem}"
                  UseLocationExpression="False"
                  Width="190"
                  Margin="0,5"
                  Grid.Row="0"
                  Grid.Column="1"
                  MaxLines="1" />
    Tuesday, February 2, 2010 12:59 AM
  • do you mean you want to add the expression textbox through xaml file?

    Tuesday, February 2, 2010 1:03 AM
  • that's not easy to do the same from xaml.
    unless you rewrite the whole flowswitchDesigner class, and bind the flowSwitchActvity to your own created designer.
    • Proposed as answer by Ye Yu - MSFT Tuesday, February 2, 2010 1:19 AM
    • Marked as answer by Special_Jimmy Tuesday, February 2, 2010 1:33 AM
    Tuesday, February 2, 2010 1:19 AM