user3326057
user3326057

Reputation: 13

WF4 Rehosted Designer

At design time,Can I dynamically change the root activiti's variables by code?
Like this:

(Designer.Context.Services.GetService<ModelService>().Root.GetCurrentValue() as RootActivity).Variables.Add(new Variable<bool>("a",false));

Give me some advice.Thanks

Upvotes: 1

Views: 309

Answers (1)

Joao
Joao

Reputation: 7476

Don't cast the ModelItem value. Changes at runtime must always be applied to the ModelItem itself.

This is the equivalent to your code but changing the ModelItem instead. Not tested.

var modelItem = Designer.Context.Services.GetService<ModelService>().Root;

modelItem.Value.Properties["Variables"].Collection.Add(new Variable<bool>("a",false));

Upvotes: 2

Related Questions