locked
Custom sequence activity deriving from System.Workflow.Activities.SequenceActivity RRS feed

  • Question

  • Hi,

    I try to create custom sequence activity. I found some sample (http://social.msdn.microsoft.com/Forums/en-US/wfprerelease/thread/f54e8eb2-29d9-46f6-ad96-766fe6fad333/). But this custom activity looks ugly (to separate nested activity using ellipses instead of arrows). My question is - how to create custom sequence activity, which will look like sequence activity.

    I also found this sample -
    <ContentPresenter x:Uid="ContentPresenter_1" Content="{Binding}" Style="{x:Static sacdt:DesignerStylesDictionary.SequenceStyle}"/>

    When I used this ContentPresenter my custom activity looks like System.Workflow.Activities.SequenceActivity, but I couldn't put on it another activity.


    I also created class, which derives from System.Workflow.Activities.SequenceActivity, but I couldn't see it in toolbox. My question is - how to create class, which derives from System.Workflow.Activities.SequenceActivity and is visible in toolbox or how to use ContentPresenter for sequence activity, which allows put on itself another activity.

    Thursday, August 26, 2010 6:18 AM

Answers

  • Hi divarius,

    I supose you have a NativeActivity with an property of type Collection<Activity> named : Activities.

    A sequence activityDesigner could look like this :

    <sap:ActivityDesigner x:Class="MyActivities.Design.ActivityWithActivitiesDesigner"
      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">
      <sap:ActivityDesigner.Resources>
        <ResourceDictionary>
      <!-- BackGround de la zone des activités -->
      <SolidColorBrush x:Key="BackGround" Color="White" />
      
      <!-- Style des TextBlock -->
      <Style TargetType="{x:Type TextBlock}">
        <Style.Setters>
          <Setter Property="Margin" Value="0 0 5 0" />
          <Setter Property="VerticalAlignment" Value="Center" />
        </Style.Setters>
      </Style>
      
      <!-- Style des Border -->
      <Style x:Key="BorderStyle" TargetType="{x:Type Border}">
        <Style.Setters>
          <Setter Property="BorderBrush" Value="LightGray" />
          <Setter Property="BorderThickness" Value="1" />
          <Setter Property="Background" Value="White" />
          <Setter Property="Padding" Value="5" />
        </Style.Setters>
      </Style>
    
      <!-- Style des Commentaires -->
      <Style x:Key="CommentStyle" TargetType="{x:Type TextBlock}">
        <Style.Setters>
          <Setter Property="FontStyle" Value="Italic" />
          <Setter Property="TextAlignment" Value="Center" />
          <Setter Property="HorizontalAlignment" Value="Center" />
          <Setter Property="VerticalAlignment" Value="Center" />
        </Style.Setters>
      </Style>
      <!-- Style des WorkflowItemsPresenter -->
      <Style TargetType="{x:Type sap:WorkflowItemsPresenter}">
        <Style.Setters>
          <Setter Property="HintText" Value="Drop activities here ..." />
          <Setter Property="ItemsPanel">
            <Setter.Value>
              <ItemsPanelTemplate>
                <!-- Oriantation des activités (de haut en bas) -->
                <StackPanel Orientation="Vertical" />
              </ItemsPanelTemplate>
            </Setter.Value>
          </Setter>
          <Setter Property="SpacerTemplate">
            <Setter.Value>
              <DataTemplate>
                <!-- 
                 StackPanel utilisé pour étandre la zone de drag and drop d'activité
                 au dela du simple Polygon
                 -->
                <StackPanel Background="{StaticResource ResourceKey=BackGround}">
                  <Polygon HorizontalAlignment="Center" Margin="5" Fill="White" Stroke="Gray" Points="0,0 16,0 8,8" />
                </StackPanel>
              </DataTemplate>
            </Setter.Value>
          </Setter>
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate TargetType="{x:Type sap:WorkflowItemsPresenter}">
                <Border Style="{StaticResource ResourceKey=BorderStyle}">
                  <ContentPresenter />
                </Border>
              </ControlTemplate>
            </Setter.Value>
          </Setter>
        </Style.Setters>
      </Style>
        </ResourceDictionary>
      </sap:ActivityDesigner.Resources>
      <Grid>
        <Grid.RowDefinitions>
          <RowDefinition Height="*"/>
          <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <TextBlock Grid.Row="0" Text="Activities" />
        <sap:WorkflowItemsPresenter Grid.Row="1" Items="{Binding Path=ModelItem.Activities}"/>
      </Grid>
    </sap:ActivityDesigner>
    
    

     

    I use it and it work fine. You coudl change styles if you want ;)


    Jérémy Jeanson MCP, MCTS http://blogs.codes-sources.com/JeremyJeanson/ (French or English spoken)
    • Proposed as answer by JeremyJeansonMVP Thursday, August 26, 2010 7:13 AM
    • Marked as answer by Divarius Thursday, August 26, 2010 8:29 AM
    Thursday, August 26, 2010 7:11 AM

All replies

  • Hi divarius,

    I supose you have a NativeActivity with an property of type Collection<Activity> named : Activities.

    A sequence activityDesigner could look like this :

    <sap:ActivityDesigner x:Class="MyActivities.Design.ActivityWithActivitiesDesigner"
      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">
      <sap:ActivityDesigner.Resources>
        <ResourceDictionary>
      <!-- BackGround de la zone des activités -->
      <SolidColorBrush x:Key="BackGround" Color="White" />
      
      <!-- Style des TextBlock -->
      <Style TargetType="{x:Type TextBlock}">
        <Style.Setters>
          <Setter Property="Margin" Value="0 0 5 0" />
          <Setter Property="VerticalAlignment" Value="Center" />
        </Style.Setters>
      </Style>
      
      <!-- Style des Border -->
      <Style x:Key="BorderStyle" TargetType="{x:Type Border}">
        <Style.Setters>
          <Setter Property="BorderBrush" Value="LightGray" />
          <Setter Property="BorderThickness" Value="1" />
          <Setter Property="Background" Value="White" />
          <Setter Property="Padding" Value="5" />
        </Style.Setters>
      </Style>
    
      <!-- Style des Commentaires -->
      <Style x:Key="CommentStyle" TargetType="{x:Type TextBlock}">
        <Style.Setters>
          <Setter Property="FontStyle" Value="Italic" />
          <Setter Property="TextAlignment" Value="Center" />
          <Setter Property="HorizontalAlignment" Value="Center" />
          <Setter Property="VerticalAlignment" Value="Center" />
        </Style.Setters>
      </Style>
      <!-- Style des WorkflowItemsPresenter -->
      <Style TargetType="{x:Type sap:WorkflowItemsPresenter}">
        <Style.Setters>
          <Setter Property="HintText" Value="Drop activities here ..." />
          <Setter Property="ItemsPanel">
            <Setter.Value>
              <ItemsPanelTemplate>
                <!-- Oriantation des activités (de haut en bas) -->
                <StackPanel Orientation="Vertical" />
              </ItemsPanelTemplate>
            </Setter.Value>
          </Setter>
          <Setter Property="SpacerTemplate">
            <Setter.Value>
              <DataTemplate>
                <!-- 
                 StackPanel utilisé pour étandre la zone de drag and drop d'activité
                 au dela du simple Polygon
                 -->
                <StackPanel Background="{StaticResource ResourceKey=BackGround}">
                  <Polygon HorizontalAlignment="Center" Margin="5" Fill="White" Stroke="Gray" Points="0,0 16,0 8,8" />
                </StackPanel>
              </DataTemplate>
            </Setter.Value>
          </Setter>
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate TargetType="{x:Type sap:WorkflowItemsPresenter}">
                <Border Style="{StaticResource ResourceKey=BorderStyle}">
                  <ContentPresenter />
                </Border>
              </ControlTemplate>
            </Setter.Value>
          </Setter>
        </Style.Setters>
      </Style>
        </ResourceDictionary>
      </sap:ActivityDesigner.Resources>
      <Grid>
        <Grid.RowDefinitions>
          <RowDefinition Height="*"/>
          <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <TextBlock Grid.Row="0" Text="Activities" />
        <sap:WorkflowItemsPresenter Grid.Row="1" Items="{Binding Path=ModelItem.Activities}"/>
      </Grid>
    </sap:ActivityDesigner>
    
    

     

    I use it and it work fine. You coudl change styles if you want ;)


    Jérémy Jeanson MCP, MCTS http://blogs.codes-sources.com/JeremyJeanson/ (French or English spoken)
    • Proposed as answer by JeremyJeansonMVP Thursday, August 26, 2010 7:13 AM
    • Marked as answer by Divarius Thursday, August 26, 2010 8:29 AM
    Thursday, August 26, 2010 7:11 AM
  • And to join activity to designer you have to add Designer attribut ot your activity like this :

    public class YourActivity : NativeActivity
    {
     // ...
    }
    

    Jérémy Jeanson MCP, MCTS http://blogs.codes-sources.com/JeremyJeanson/ (French or English spoken)
    Thursday, August 26, 2010 7:13 AM
  • Thank you so much. I have now another question - do you know how to hide public property or InArgument in properties window? I would like to hide property (collection, that contains children activity). When I set private accessor for this property I can't add another activity to my sequence. Is it possible?
    Thursday, August 26, 2010 8:36 AM
  • Yes,

    Add attribut [Browsable(false)] to heach argument to hide your properties

     

    http://msdn.microsoft.com/en-us/library/system.componentmodel.browsableattribute.aspx


    Jérémy Jeanson MCP, MCTS http://blogs.codes-sources.com/JeremyJeanson/ (French or English spoken)
    Thursday, August 26, 2010 8:39 AM
  • I missed attibut in a latter message :

    ...

    And to join activity to designer you have to add Designer attribut ot your activity like this :

    [Designer(typeof(YourActivityDesigner))]
    public class YourActivity : Activity
    {
     // ...
    }
    

    Jérémy Jeanson MCP, MCTS http://blogs.codes-sources.com/JeremyJeanson/ (French or English spoken)
    Thursday, August 26, 2010 8:43 AM