none
How to disable delete command for certain activities inside the composite activity

    Question

  • Hi

    I had build up a composite activity, this composite activity basically contains a few activities, some of the activities are not allowed to delete. Is there a way to disable the delete command using WF APIs, instead of hooking up the keydown and context menu event for those activities?

    thanks 

    Thursday, September 30, 2010 9:36 AM

Answers

  • Hi again.

    I have spent some time rediscovering the CommandBinding on designer view approach you already use, and writing a few details about it.

    For ways to invoke the original delete functionality there is a) reflection (easy) b) interesting tricks like changing the command binding to point to a different command, harder, but I think I figured out how to do that. The one other idea I had along the way is putting Executed CommandBindings on the activity designer, instead of designer view but that has drawbacks too.

    Anyway, posted sample code here, let me know what you think.
    Tim

    • Marked as answer by jhlim21 Monday, November 01, 2010 8:54 AM
    Friday, October 22, 2010 5:51 PM
    Moderator

All replies

  • Hello

    Would you provide a bit more information concerning your composite activity? Is this composite activity a standalone dll that you are adding to other workflows or are you including the xaml file in the project?

    Also you mention other out of the box activities that don't allow the delete when included in your composite. Could you be more specific?

    Thursday, October 14, 2010 5:28 PM
    Moderator
  • if your composite activity is inherited from ICompositeView directly, you can control the OnItemsDeleted.

    it's not like CopyPaste, you can control the CanCopyPaste function, for delete, there is no such interface open to you.

    as long as the selected object is workflowViewElement and it's not the root designer, the CanDelete will be true internally.

    so the only way you can disable those activities delete command is to control the delete implementation in OnItemsDeleted.

     

    Let me know if you need sample code.

    Thursday, October 14, 2010 6:12 PM
  • Hi Ye Yu

    My composite activity is inherited from IActivityTemplateFactory directly and t, not ICompositeView. Basically It is a kind of sequence workflow presentation, contains a few pre-defined activities (inside WorkflowItemPresenter) that are NOT ALLOWED to delete and change the activities sequence (drag and drop operation need to be disabled for this). Beside that, user also allow to drag and delete their own activity to this composite activity (inside WorkflowItemsPresenters). Do you think is it better go for ICompositeView approach or any suggestion? It would be helpful if you can provide the sample code if you think this should go for ICompositeView

     

    Thanks in advance.

    Monday, October 18, 2010 9:15 AM
  • according to your description, I don't think IActivityTemplateFactory can meet your request.

    the only way is you create a custom sequence activity designer and bind it to the current sequence activity.

    and then put the new sequence activity designer into the IActivityTemplateFactory.

    even with this way, as I have explained above, you can just disable the delete command from OnDeleteCommand level, because there is no public CanDelete interface.

    if you need the sample code, can you leave me your mail address, because it's too long to paste here.

    I will mail you the sample code tomorrow.

     

    Monday, October 18, 2010 5:55 PM
  • This is for a reusable activity in VS, rather than a rehosted app scenario? The reason I ask is that if you are doing your own rehosted app it is fairly easy to intercept the delete command.
    Tim
    Monday, October 18, 2010 6:16 PM
    Moderator
  • This is for a reusable activity in VS, rather than a rehosted app scenario? The reason I ask is that if you are doing your own rehosted app it is fairly easy to intercept the delete command.
    Tim

    Hi Tim,

    At this moment, my custom activities are hosted in VS, In future, I will move my activities into my own rehosted application. It is good if I can have both hosted apps

    Hi Ye Yu,

    Indeed, I have my own custom sequence activity that inside the IActiviyTemplateFactory as a container. What I am doing now is intercepting the designer Loaded and Unloaded event, by adding my own event command event handler. For loaded event, something like below code

     

    void Loaded(object sender, RoutedEventArgs e)
    {
     ...
      foreach (CommandBinding cb in this.Designer.CommandBindings)
      {
        if (cb.Command.Equals(ApplicationCommands.Delete))
        {
         cb.CanExecute += new CanExecuteRoutedEventHandler(cb_DeleteCommandCanExecute);
        }
     ...
    }
    
    void OnDeleteCommandCanExecute(object sender, CanExecuteRoutedEventArgs e)
    {
      bool canDelete = false;
      Selection selection = this.Context.Items.GetValue<Selection>();
      if (selection != null & selection.SelectionCount > 0)
      {       
        canDelete = selection.SelectedObjects.All(p => p.ItemType != typeof(AppActivity));   
      }
      e.CanExecute = canDelete;
     
    }
    
    Too bad, the above code will break the existing CanDelete logic, and use my own CanDelete logic. 

     

    Here you go my email jinho.lim at live.com

    Thanks a lot

    Tuesday, October 19, 2010 9:46 AM
  • I have sent you the mail.

    Please let me know if you have more questions.

    Wednesday, October 20, 2010 6:42 PM
  • I have sent you the mail.

    Please let me know if you have more questions.

    Hi Ye Yu,

    I haven't received any emails from you so far. 

    Thursday, October 21, 2010 8:22 AM
  • I have sent it again, but it's said not a valid mail address.

    can you send a mail to me first?

    sophy_yuye@hotmail.com

    Friday, October 22, 2010 1:13 AM
  • Hi again.

    I have spent some time rediscovering the CommandBinding on designer view approach you already use, and writing a few details about it.

    For ways to invoke the original delete functionality there is a) reflection (easy) b) interesting tricks like changing the command binding to point to a different command, harder, but I think I figured out how to do that. The one other idea I had along the way is putting Executed CommandBindings on the activity designer, instead of designer view but that has drawbacks too.

    Anyway, posted sample code here, let me know what you think.
    Tim

    • Marked as answer by jhlim21 Monday, November 01, 2010 8:54 AM
    Friday, October 22, 2010 5:51 PM
    Moderator
  •  

    It is a great blog. Thanks Tim.

     

    Another idea pop up from my mind. I am just wondering where there is no delete helper class for us, something like DrapDropHelper, CutCopyPasteHelper static class, allow us to perform a verification on whether items can be deleted or not.

     

    Monday, November 01, 2010 8:54 AM
  • Yes there is a DeleteHelper class, it is just not public. :-(
    You can use Reflection to invoke it, at some risk of being broken against future framework versions.

    You could use Connect to request the API be made public in future versions. For Workflow Foundation (3 and 4), the connect portal is https://connect.microsoft.com/wf

    Tim

    Monday, November 01, 2010 5:33 PM
    Moderator