locked
Custom activity designer with ActivityActions RRS feed

  • Question

  • Hello,

    I have been trying to find answer to the following problem for hours, without success. I need to create a custom designer for an activity which has activity delegates, for example:

        Public Class SomeActivity
            Inherits NativeActivity
    
            Public Property Foo As ActivityAction(Of String)
            Public Property Bar As ActivityAction(Of String)
    
            Protected Overrides Sub Execute(context As NativeActivityContext)
            End Sub
        End Class

    When using WF4.5, the default designer for activities like this is simply awesome. The designer automatically creates views for activity delegates and allows the user to define names for delegate variables:

    This is absolutely brilliant and works for most of the cases. However, I have not found any hint how to add additional content to  a such designer. If I create a custom designer, I lose the automatically generated presenters for delegates:

    <sap:ActivityDesigner x:Class="ActivityDesigner1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
        xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation">
        <Grid>
            <Label>Hello, world!</Label>
            <!--What to insert here to include activity delegates?-->
        </Grid>
    </sap:ActivityDesigner>
    

    The result does not have delegates, as the original designer is replaced with the grid:


    I can, obviously, use WorkflowItemPresenter and bind to appropriate Handlers, but I need to build everything from scratch:

    <sap:ActivityDesigner x:Class="ActivityDesigner1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
        xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation">
        <StackPanel>
            <Label>Hello, world!</Label>
            <Label>Foo</Label>
            <sap:WorkflowItemPresenter Item="{Binding Path=Foo.Handler}" HintText="Drop here"/>
            <Label>Bar</Label>
            <sap:WorkflowItemPresenter Item="{Binding Path=Bar.Handler}" HintText="Drop here"/>
        </StackPanel>
    </sap:ActivityDesigner>
    

    This works basically, but there is no way to define activity variable names as in the default activity designer:

    I could hack in something to re-implement what seems to be so well implemented in the default activity designer. Unfortunately this feels like re-inventing the square wheel...

    So to the question: is it possible to create a custom activity designer which includes both some custom content and the automatically generated placeholders for activity delegates? Any hints or examples are greatly appreciated.

    Kind regards,

    Heikki

    Tuesday, November 24, 2015 3:39 PM

All replies

  • Hi,

    Please refer to the sample:

    #How to create a Custom Activity Designer with Windows Workflow Foundation (WF4)

    http://blogs.msdn.com/b/rjacobs/archive/2011/08/14/how-to-create-a-custom-activity-designer-with-windows-workflow-foundation-wf4.aspx

    #How to: Create a Custom Activity Designerhttps://msdn.microsoft.com/en-us/library/dd489419(v=vs.100).aspx


    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, November 25, 2015 9:33 AM
  • Pello Pengzhen,

    I have read those examples, and I know how to create custom activity designers. I know how to create a drop zone to an activity designer using WorkflowItemPresenter, as I wrote in my question. However, I do not know how to create a drop zone for an activity delegate in a custom activity designer.

    It is possible to use WorkflowItemPresenter to create drop zone for ActivityDelegate.Handler, which is an Activity. However, the drop zone created this way does not include placeholder(s) for delegate argument(s). I want to create a custom activity designer which has both custom content defined by me and the automatically generated drop zones for activity delegates. 


    Wednesday, November 25, 2015 10:12 AM
  • FYI,

    I found a dirty hack to the problem using wpf inspector.  Assuming the built-in layout of the ActivityDesigner does not change, one can use VisualTreeHelper to find the StackPanel where the ActivityDesigner content is inserted. You can then insert custom content to the StackPanel. This seems to work, altough this is not quite nice:

    Class ActivityDesigner1
    
    
        Public Overrides Sub OnApplyTemplate()
            MyBase.OnApplyTemplate()
    
            Dim contentStack = FindContentStack()
            If contentStack IsNot Nothing Then
                contentStack.Children.Insert(0, New Label() With {.Content = "Hello, world!"})
            End If
        End Sub
    
        Private Function FindContentStack() As StackPanel
            Dim border = VisualTreeHelper.GetChild(Me, 0)
            If border IsNot Nothing Then
                Dim grid = CType(VisualTreeHelper.GetChild(border, 0), Grid)
                If grid IsNot Nothing Then
                    Dim count = VisualTreeHelper.GetChildrenCount(grid)
                    For i As Integer = 0 To count
                        Dim contentStack = TryCast(VisualTreeHelper.GetChild(grid, i), StackPanel)
                        If contentStack IsNot Nothing Then Return contentStack
                    Next
                End If
            End If
            Return Nothing
        End Function
    
       
    End Class

    Result:


    If anyone knows a better approach, please let me know.

    • Proposed as answer by Angie Xu Thursday, December 3, 2015 8:40 AM
    Wednesday, November 25, 2015 11:47 AM