locked
I miss CanInsertActivities RRS feed

  • Question


  • In WF 3.5 I use SequentialWorkflowRootDesigner.CanInsertActivities() to determin if a particular Activity that was being dragged from the toolbox could be added to the target composite activity. This was a straight forward and easy way to check many things prior to allowing the drop event to continue; if validation/business rules are not met, you simply return false.

     

    However, in WF4 I’m not able to figure out the best place to perform these type of checks. I’m using an ActivityDesigner and setting AllowedItemType to the Activity type. This works fine for that one check. But I need somewhere to check other business rules before the user is allowed to drop the Activity.   One place I know I can check is the WorkflowDesigner.ModelChanged event but I rather not have to traverse the whole model. Another place (more ideal I think) is in the WorkflowItemsPresenter.PreviewDrop event within my ActivityDesigner. In both cases I’m able to determine what the user is attempting to drop but I don’t know how to stop the drop from occurring. In my ActivityDesigner   I set my WorkflowItemsPresenter.AllowDrop = false, but that doesn’t stop the current attempt to drop the activity, rather it does stop all subsequent attempts to drop, which is something I don’t want to happen. I also thought setting DragEventArgs.RoutedEvent = false (inside the PreviewDrop event of the ActiviyPresenter) would cancel the rest of the drop attempt event but that didn’t work they way I thought it was supposed to. It would seem that the best place to do this kind of check would be in the ICompositeView interface (something like bool CanAddItems() ) something similar to the   bool CanPasteItems() method.

     

    Anyway, if you have an idea of how to go about accomplishing this scenario in WF4, I’d appreciate your comments.

     

    ( I miss: bool CanInsertActivities() )


    Sham Singh
    • Moved by Andrew_Zhu Wednesday, March 3, 2010 9:36 AM (From:Windows Workflow Foundation)
    Friday, February 26, 2010 12:14 AM

Answers

  • Hi Sham,
    You are close - you should be able to stop the drop from occurring by overriding certain events in ActivityDesigner (as you say), similar to this:

            protected override void OnPreviewDragEnter(DragEventArgs e)
            {
                e.Effects = DragDropEffects.None;
                e.Handled = true;
            }
    
            protected override void OnPreviewDragOver(DragEventArgs e)
            {
                e.Effects = DragDropEffects.None;
                e.Handled = true;
            }
    
            protected override void OnPreviewDrop(DragEventArgs e)
            {
                e.Effects = DragDropEffects.None;
                e.Handled = true;
            }


    - Or I think setting AllowDrop = false can work too, if you do it in OnPreviewDragEnter() instead of OnPreviewDrop().

    Implementing ICompositeView should not be required.

     Tim

     

    Wednesday, March 3, 2010 9:57 PM

All replies

  • Hi Sham,
    You are close - you should be able to stop the drop from occurring by overriding certain events in ActivityDesigner (as you say), similar to this:

            protected override void OnPreviewDragEnter(DragEventArgs e)
            {
                e.Effects = DragDropEffects.None;
                e.Handled = true;
            }
    
            protected override void OnPreviewDragOver(DragEventArgs e)
            {
                e.Effects = DragDropEffects.None;
                e.Handled = true;
            }
    
            protected override void OnPreviewDrop(DragEventArgs e)
            {
                e.Effects = DragDropEffects.None;
                e.Handled = true;
            }


    - Or I think setting AllowDrop = false can work too, if you do it in OnPreviewDragEnter() instead of OnPreviewDrop().

    Implementing ICompositeView should not be required.

     Tim

     

    Wednesday, March 3, 2010 9:57 PM
  • Thanks, Tim. Overriding those three methods along with setting e.Effects and e.Handled per your suggestion does exactly what I'm looking for. You're also write about being "close" as I have overrode those methods before but my property settings were not quite right.

    Thanks again.
    Sham Singh
    Friday, March 5, 2010 6:36 PM