locked
Auto Binding Constraint doesn't update the UI RRS feed

  • Question

  • I needed a way to auto bind an activities inArgument to its parent activities delegateInArguments (property defined in an activity action).

    Picture dropping a WriteLine activity into an foreach<string> and having the foreach's argument automatically placed into the in argument of the writelines text property - binding it as it is dropped.

    I have created the constraint, and it works, including changing the binding to the parent or setting the property back to null if not in a parent.  My problem is that the UI doesn't reflect this.  It actually looks like it is doing nothing - I only know it works because it comes back correctly after a save and load of the workflow pattern.

    I'm guessing that I somehow need to refresh the model item?

    How do I refresh the model item from within a constraint?

    If it helps I have included the code for my constraint below, but note that my need is not as simple as the above example, so this does a couple of other things that don't make sense to this question.

    static Constraint CheckParent()
        {
          DelegateInArgument<GetTaskPermissionsActivity> element = new DelegateInArgument<GetTaskPermissionsActivity>();
          DelegateInArgument<ValidationContext> context = new DelegateInArgument<ValidationContext>();
          Variable<bool> result = new Variable<bool>();
          Variable<string> taskActivityHoleName = new Variable<string>() { Default = "NotSetYet" };
          DelegateInArgument<System.Activities.Activity> parent = new DelegateInArgument<System.Activities.Activity>();
    
          return new Constraint<GetTaskPermissionsActivity>
          {
            Body = new ActivityAction<GetTaskPermissionsActivity, ValidationContext>
            {
              Argument1 = element,
              Argument2 = context,
              Handler = new Sequence
              {
                Variables =
                {
                  result ,
                  taskActivityHoleName ,
                },
                Activities =
                {
                  //Loop through all parent activities
                  new ForEach<System.Activities.Activity>
                  {                
                    Values = new GetParentChain
                    {
                      ValidationContext = context                  
                    },
                    Body = new ActivityAction<System.Activities.Activity>
                    {  
                      Argument = parent, 
                      Handler = new Sequence()
                        {  Activities = 
                          {  
                            //Look for the task hole
                            new If()
                            {                     
                              Condition = new InArgument<bool>((env) => typeof(ITaskHoleActivity).IsAssignableFrom( parent.Get(env).GetType())),                    
                              Then = new Sequence()
                              {Activities= { new Assign<bool> {Value = true,To = result},
                                       new Assign<string> {
                                                        Value = new InArgument<string>((env) => ((ITaskHoleActivity)parent.Get(env)).InPropertiesVariableName),
                                                        To = taskActivityHoleName 
                                                      },
                                     }  
                              }
                            },
                            //Look For the task activity
                            new If()
                            {                     
                              Condition = new InArgument<bool>((env) => typeof(ITaskActivity).IsAssignableFrom( parent.Get(env).GetType())),                    
                              Then = new Sequence()
                              {Activities= { new Assign<bool> {Value = true,To = result},
                                 
                                        new Assign<InArgument<Guid>> {
                                                        Value = new InArgument<InArgument<Guid>>((env) => new VisualBasicValue<Guid>(((ITaskActivity)parent.Get(env)).UniqueActivityName + taskActivityHoleName.Get(env) + ".TaskGuid")),
                                                        To = new OutArgument<InArgument<Guid>>((env) => element.Get(env).TaskGuid )
                                                      },
                                      }  
                              }
                            }
                          }
                        }
                    }                
                  },
                                new If()
                            {                     
                              Condition = new InArgument<bool>((env) => result.Get(env)==false),                    
                              Then = new Sequence()
                              {
                                //no parent task found
                                Activities= { new Assign<InArgument<Guid>> {
                                                        Value = new InArgument<InArgument<Guid>>((env) => null),
                                                        To = new OutArgument<InArgument<Guid>>((env) => element.Get(env).TaskGuid )
                                                      },
                                      }  
                              }
                            }
                }
              }
            }
          };
        }

     


    Jason Bolstad
    Tuesday, September 7, 2010 5:00 AM

Answers

  • Hi Patrick

    Cheers for your help of this, but I have decided to give up on constraint doing the auto binding.

    I ended up with two issues. 

    1. UI not updating once I rebound (Yes I did have TwoWay set:)

    2. Constraints execute at run time too, and it was destroying the binding when it ran.

    Instead I have fixed my issue by creating an activity that combines execution properties with an in argument.  At execution time I use the inarg if it is set otherwise I used the execution property.  My custom constraint now only makes sure that the inarg has a value if not inside the activity that provides the execution property.

    Cheers for all you help on this, it is much appreciated.

     


    Jason Bolstad
    • Marked as answer by Jason Bolstad Thursday, September 9, 2010 12:36 AM
    Thursday, September 9, 2010 12:35 AM

All replies

  • When declaring the binding for the WorkflowItem(s)Presenter in the designer, are you setting {Binding Mode=TwoWay}? I'm not sure if that will do the trick, but it's a quick thing to try if it isn't set that way already-
    Wednesday, September 8, 2010 5:55 PM
  • Hi Patrick

    Cheers for your help of this, but I have decided to give up on constraint doing the auto binding.

    I ended up with two issues. 

    1. UI not updating once I rebound (Yes I did have TwoWay set:)

    2. Constraints execute at run time too, and it was destroying the binding when it ran.

    Instead I have fixed my issue by creating an activity that combines execution properties with an in argument.  At execution time I use the inarg if it is set otherwise I used the execution property.  My custom constraint now only makes sure that the inarg has a value if not inside the activity that provides the execution property.

    Cheers for all you help on this, it is much appreciated.

     


    Jason Bolstad
    • Marked as answer by Jason Bolstad Thursday, September 9, 2010 12:36 AM
    Thursday, September 9, 2010 12:35 AM