locked
Custom designer for switch activity RRS feed

  • Question

  • I have been banging my head from my previous question about the switch activity, and without any luck so far from a XAML perspective. So can you override the flow switch and flow decision activity designers to make it visually different?

    If so, what are the requirements within the XAML, specifically relating to the binding of the expression to an expression textbox? Do I really need to write a custom switch activity?
    Wednesday, February 3, 2010 9:03 PM

Answers

All replies

  • Jimmy, can I ask why you have to use the XAML to add the expression content on switch designer?
    can you consider to use grid.children.add?
    because as you said, it's really hard to write the custom designer, and some of the behaviors of flowswitch designer is controlled in flowchart designer.

    Wednesday, February 3, 2010 9:20 PM
  • Hi Ye Yu,

    What I want to be able to do is remove the properties grid from a rehosted designer. Being able to have the expression property on the switch/descision activity on the rehosted design canvas and allow users to edit, instead of using the properties grid means I can hide the properties grid altogether.

    At the moment the expression can be viewed as a hover over / pop up / tooltip type of display.

    I guess the question is where is the most appropriate place to make changes to the flow switch and flow activity's visual look and feel? If it means having to recode a switch that's not a very appealing option!

    FlowChart is not that extensible either....



    Wednesday, February 3, 2010 10:47 PM
  • I think you can do this way
    1. in your rehost app, add modelchange event
    2. when model change, if there is a new flowswitch designer added, use the code I pasted in following thread to add the ExpressionTextbox, and bind the event like hover over

    http://social.msdn.microsoft.com/Forums/en-US/wfprerelease/thread/6279d356-e5b7-47f2-b2d3-8d7cfe6b33e4
    Wednesday, February 3, 2010 11:03 PM
  • Thanks Ye Yu, I was hoping for a default solution... maybe in a service pack? LOL ;-)

    Your advise is still great, thanks again I'll give it a shot.
    Wednesday, February 3, 2010 11:18 PM
  • Hey Ye Yu, I used your code and modified for my purpose (as we use an activitydesigner -> flowchart -> flowswitch), alas the code returns a null reference after dragging the switch onto the designer for the first time. I have added code to prevent a null reference expection, code:

            public void wd_ModelChanged(object sender, EventArgs e)
            {
                if (wd.View != null)
                {
                    ModelProperty modelProperty = wd.Context.Services.GetService<ModelService>().Root.Properties["Implementation"];
    
                    ModelItem modelItem = modelProperty.Value;
                    WorkflowViewElement element = modelItem.View as WorkflowViewElement;
    
                    if (element.Content != null)
                    {
                        ModelItemCollection nodeCollection = modelItem.Properties["Nodes"].Collection;
    
                        foreach (ModelItem item in nodeCollection)
                        {
                            if (item.ItemType == typeof(FlowSwitch)) // && item.Properties["Expression"].Value != null)
                            {
    
                                WorkflowViewElement nodeElement = item.View as WorkflowViewElement;
    
                                ExpressionTextBox expressionTextBox = new ExpressionTextBox();
                                // expressionTextBox.Content = item.Properties["Expression"].ComputedValue.ToString();
                                expressionTextBox.HintText = "Enter an expression here.";
    
                                // string contentString = item.Properties["Expression"].ComputedValue.ToString();
                                if (nodeElement != null) 
    { // the next line will produce null reference as it is null on first change Grid grid = nodeElement.Content as Grid; grid.Children.Add(expressionTextBox); } item.Properties["Expression"].SetValue(expressionTextBox.Content); } if (item.ItemType == typeof(FlowDecision) && item.Properties["Condition"].Value != null) { WorkflowViewElement nodeElement = item.View as WorkflowViewElement; ExpressionTextBox expressionTextBox = new ExpressionTextBox(); //expressionTextBox.Content = item.Properties["Condition"].Value.Properties["ExpressionText"].ComputedValue.ToString(); expressionTextBox.HintText = "Enter a condition here."; if (nodeElement != null) { Grid grid = nodeElement.Content as Grid; grid.Children.Add(expressionTextBox); } } } } } wd.Flush(); }
    Whya is the Switch.Content null when first dragged onto the designer (which invokes wd_ModelChanged), then after the second change it works? but Any advise would be great!
    Thursday, February 4, 2010 7:10 PM
  • can you double check whether your item.view is null at first change?(item means the flowswitch modelitem)
    if it's null, that's because when the modelchange happens, the view of the modelitem hasn't been generated.

    you can refer to my answer on this thread to solve the problem.

    http://social.msdn.microsoft.com/Forums/en-US/wfprerelease/thread/674f3ec4-493f-40b3-a2d7-1dab4200fe0a
    • Marked as answer by Special_Jimmy Thursday, February 4, 2010 11:45 PM
    Thursday, February 4, 2010 7:34 PM
  • That's done the trick, albeit a little untidy given the new expressionTextBox sits over top of the switch.

    Example of image:

    http://yfrog.com/elflowswitchj

    Any advise for tidying up the presentation? You may now be able to see why I thought the custom designer was the way to override the default "design" of the flow switch.

    Thursday, February 4, 2010 9:45 PM
  • I think the way is that you shorten the width of the ETB to fit the switch designer, and the ETB support multilines.

    I understand why you want to override the default "design" of the flow switch, however, it's really not small work as I mentioned above.

    Thursday, February 4, 2010 11:17 PM