none
Customizing ActivityDesigner in Workflow 4.0

    General discussion

  • I thought of having some customized ActivityDesigner in a DLL, not executable (as in EXE, we could have app.xaml file). To achieve this,I created a BaseDesigner which is derived from ActivityDesigner.

     

     

    public class BaseDesigner : System.Activities.Presentation.ActivityDesigner

    { public BaseDesigner(){}}

    Added a ResourceDictionary & created the Style for BaseDesigner

    <ResourceDictionary x:Uid="ResourceDictionary_1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

     

     

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

     

     

    xmlns:swd="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"

     

     

    xmlns:swdv="clr-namespace:System.Activities.Presentation.Validation;assembly=System.Activities.Presentation"

     

     

    xmlns:proj="clr-namespace:RehostedDebugging"

     

     

    xmlns:local="clr-namespace:WF4ActivityDesignerLibrary.ActivityDesigner"

     

     

    xmlns:sadv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation">

     

     

     

    <Style TargetType="{x:Type swd:ActivityDesigner}">

     

     

     

    <Setter Property="Template">

     

     

     

    <Setter.Value>

    (ControlTemplate from Kushals post - http://blogs.msdn.com/b/kushals/archive/2010/01/04/base-designer-with-additional-adornments.aspx)

    I changed the ControlTemplate to hide the Icon on the ActivityDesigner & set TargetType to "BaseDesigner" (Intially TargetType was "local:BaseDesigner" but that didn't work so changed to "swd:ActivityDesigner".

    Now created 2 custom activites & their designers. In one of the custom designer, I am merging the created ResourceDictionary (ActivityDesigner1.xaml).

     ActivityDesigner1.xaml

    <local:BaseDesigner x:Class="WF4ActivityDesignerLibrary.ActivityDesigner.ActivityDesigner1"
              xmlns:local="clr-namespace:WF4ActivityDesignerLibrary.ActivityDesigner"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:swd="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
      xmlns:swdv="clr-namespace:System.Activities.Presentation.Validation;assembly=System.Activities.Presentation"  
    xmlns:sadv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation"
              xmlns:proj="clr-namespace:RehostedDebugging">
      <local:BaseDesigner.Resources>
        <ResourceDictionary>
          <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/WF4ActivityDesignerLibrary;component/CustomWorkflowElementDesignerTemplate.xaml"/>
          </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
      </local:BaseDesigner.Resources></local:BaseDesigner>
    

    In another designer, directly putting the ControlTemplate code in Resources section (ContainerActivityDesigner.xaml).

    ContainerActivityDesigner.xaml

    <

     

     

    local:BaseDesigner ...add the references from above code

    <local:BaseDesigner.Resources>

     

     

     

    <ResourceDictionary>... Put ControlTemplate code here</ResourceDictionary>

     

     

     

    </local:BaseDesigner.Resources>

     

     

     

    <local:BaseDesigner.Style>

     

     

     

    <Style TargetType="{x:Type local:BaseDesigner}">

     

     

     

    <Style.Triggers>

     

     

     

    <DataTrigger Binding="{Binding Path=ShowExpanded}" Value="false">

     

     

     

    <Setter Property="Template" Value="{StaticResource CustomTemplate}"/>

     

     

     

    </DataTrigger>

     

     

     

    </Style.Triggers>

     

     

     

    </Style>

     

     

     

    </local:BaseDesigner.Style>

    Save files, Add a WF console app & add a reference to above created project. Now drag the custom activites on Workflow.xaml file. You will notice the difference (there is no change in first designer while another designer hides the activity icon).

    I am not sure if I am missing anything. I tried merging the ResourceDictionary even in code behind file of BaseDesigner but no success. Now suppose if I need to customize ActivityDesigner & create multiple custom activity designers, how could I achieve this as it is practically not possible to put the ControlTemplate code in each individual activity designer.

    I have gone thru the Kushals post at http://blogs.msdn.com/b/kushals/archive/2010/01/04/base-designer-with-additional-adornments.aspx) but in that, App.xaml file used & in cs file, he is actually getting the style & applying that style to MS provided activity designers. In my case, it is custom designer & w/o any app.xaml file. Any help would be appreciable.

    • Moved by Xinyan Ma 马欣妍 Wednesday, April 20, 2011 5:21 AM forum cleanup (From:MSDN, TechNet, and Expression Profile and Recognition System Discussions)
    Thursday, August 12, 2010 10:41 AM