locked
WF4 rehosted - get selected activities in a flowchart RRS feed

  • Question

  • I select a few activities in a flowchart and trying to delete them. In the ModelChanged event of the current ModelService, i am trying to get which items were selected :

     var selections = Designer.Context.Items.GetValue<Selection>().SelectedObjects;

    I would expect a list containing my selections, but instead i get back the flowchart which contains those items. I can't figure out how to reach those specific activities.

    I saw an answer to a similar question :

                NativeActivity activity = wd.Context.Items.GetValue<Selection>().
      PrimarySelection.GetCurrentValue() as NativeActivity;

    but this give me the same result, meaning the flowchart containing the activities which are to be deleted. 

    Is there any way to get over the flowchart and retrieve those items? 

    Tuesday, October 7, 2014 6:22 PM

All replies

  • Hi,

    [quote]  In the code below, I am simply providing a lambda that sets a combo box items to the selected items.

    wd.Context.Items.Subscribe<Selection> (sel => SelectedItems.ItemsSource = sel.SelectedObjects);
    

    You can also just get the Selection item from the Items collection and inspect it, or you can explicitly set it to a model item of your choosing and the designer will update accordingly. [/quote]

    Source from http://social.msdn.microsoft.com/Forums/en-US/79a26958-33c8-48ac-a58d-a8ecb49b95ae/get-an-event-in-a-rehosted-designer-for-activity-selection?forum=wfprerelease


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, October 8, 2014 2:17 AM
  • Hello, 

     Thank you for your response, I've read that yesterday before posting this, it didn't work. Right after i instantiate my designer i add that piece of code: 

         _wd = new WorkflowDesigner();

                      ..................................................

                    _wd.ModelChanged += _wd_ModelChanged;
                    _wd.Context.Items.Subscribe<Selection>(sel => models = sel.SelectedObjects.ToList());

                   .........................................

            List<ModelItem> models = new List<ModelItem>();
            void _wd_ModelChanged(object sender, EventArgs e)
            {
                Console.WriteLine(sender.ToString());
                Console.WriteLine(models.Count);
            }


    I select both of my existing activities here by pressing CTRL and when i click delete i get into the that void _wd_ModelChanged above. 

     

    And here comes my issue, what i receive here is my Flowchart containing those activities and not the two of them selected for the deletion operation. 


    Wednesday, October 8, 2014 5:47 AM