locked
NativeActivity/how activity drop? RRS feed

  • Question

  • Hello,

    Here is simple Test Activity class

    public sealed class Test : NativeActivity {

         public Activity Body { get; set;}

         protected override void Execute(NativeActivityContext context)
        {

                 if(Body != null) {

                    // Do whatever from the Body activity

                }

        }

    }

    I dropped this activity on my workflow...then how do I set the Body from designer?

    I thought that I could drag some activity(ex, WriteLine) and drop on this Test activity to set the Body..However, it didn't work.

    In the Properties window, Body is there under Misc section. I am not sure how I set an activity to the Body property.

    Please help me some step how to do this.

    Thanks,

    Tuesday, February 28, 2012 9:47 PM

Answers

  • Hi,

    In this case, we'll need to create a custom activity designer, bind a WorkflowItemPresenter in the designer to the Body to enable editing it.

    <!-- Copyright (c) Microsoft Corporation. All rights reserved -->
    <sap:ActivityDesigner x:Class="Microsoft.Samples.UsingWorkflowItemPresenter.SimpleNativeDesigner"
        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" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="300" d:DesignWidth="300">
        <sap:ActivityDesigner.Resources>
            <DataTemplate x:Key="Collapsed">
                <StackPanel>
                    <TextBlock>This is the collapsed view</TextBlock>
                </StackPanel>
            </DataTemplate>
            <DataTemplate x:Key="Expanded">
                <StackPanel>
                    <TextBlock>Custom Text</TextBlock>
                    <sap:WorkflowItemPresenter Item="{Binding Path=ModelItem.Body, Mode=TwoWay}"
                                            HintText="Please drop an activity here" />
                </StackPanel>
            </DataTemplate>
            <Style x:Key="ExpandOrCollapsedStyle" TargetType="{x:Type ContentPresenter}">
                <Setter Property="ContentTemplate" Value="{DynamicResource Collapsed}"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=ShowExpanded}" Value="true">
                        <Setter Property="ContentTemplate" Value="{DynamicResource Expanded}"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </sap:ActivityDesigner.Resources>
        <Grid>
            <ContentPresenter Style="{DynamicResource ExpandOrCollapsedStyle}" Content="{Binding}" />
        </Grid>
    </sap:ActivityDesigner>

    Then, you can decorate the activity:

    [Designer(typeof(SimpleNativeDesigner))]

    public sealed class Test : NativeActivity {

    ...

    For the detailed information, you can refer to

    Custom Composite Designers - Workflow Item Presenter

    http://msdn.microsoft.com/en-us/library/dd759032.aspx


    Leo Tang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by LeoTang Tuesday, March 6, 2012 9:07 AM
    Thursday, March 1, 2012 10:21 AM