I add a callback
_workflowDesigner.Context.Items.Subscribe<Selection>(SelectionChanged);
in a re-hosted designer, and try to find the related activity in the callback. Then I assume I could add some event handler to offer user a way to manipulate some property of it. (i.e. add event handler
(target as WorkflowViewElement).PreviewKeyDown += new KeyEventHandler(DoSomeWorkBySomeKeyDown);
) But this way looks not working, the activity cannot be found by (Selection selection).
I was also trying to add the event handler in following code, but it only work right after the activity was added in WF. After click other activity container, then select the activity again, the event handler will lost and will not be fired anymore.
public sealed class WrappedCodeActivity : IActivityTemplateFactory
{
private CodeActivityAbc codeActivityAbc = new CodeActivityAbc() { DisplayName = "abc" };
public WorkflowViewElement oneWorkflowViewElement;
public Activity Create(DependencyObject target)
{
oneWorkflowViewElement = (WorkflowViewElement)target;
(target as WorkflowViewElement).PreviewKeyDown += new KeyEventHandler(DoSomeWorkBySomeKeyDown);
return codeActivityAbc;
}
. . .
Did anybody have any idea to to this? Please put any thought you have.
_workflowDesigner.Context.Items.Subscribe<Selection>(selection =>
{
foreach (var item in selection.SelectedObjects)
{
Console.WriteLine("Activity of type: " + item.ItemType + " selected.");
if (item.ItemType == typeof(Sequence))
{
// Get Sequence object
var seq = item.GetCurrentValue() as Sequence;
// Add variable to Sequence
seq.Variables.Add(new Variable<int>("NewIntegerVar", 10));
}
}
});