カスタム複合デザイナー - Workflow Item Presenter

WorkflowItemPresenter は、任意のアクティビティを配置できる "ドロップ ゾーン" を作成できる、WF デザイナー プログラミング モデル内の主要な型です。 このサンプルでは、このような "ドロップ ゾーン" を表示するアクティビティ デザイナーの構築方法を示します。

WorkflowItemPresenter サンプルでは次を示します。

  • WorkflowItemPresenter を使用したカスタム アクティビティ デザイナーの作成

  • メタデータ ストアを使用したカスタム デザイナーの登録。

  • 宣言および命令による再ホストされたツールボックスのプログラミング。

サンプルの詳細

このサンプルのコードを次に示します。

  • カスタム アクティビティ デザイナーは SimpleNativeActivity クラス用に作成されます。

  • WorkflowItemPresenter を使用してカスタム アクティビティ デザイナーを作成します。

<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">
    <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>

ModelItem.Body にバインドする WPF のデータ バインディングの使用に注意してください。 ModelItem は、デザイナーが使用されている、基になるオブジェクト (この例では SimpleNativeActivity) を参照する ActivityDesigner のプロパティです。

サンプルをセットアップ、ビルド、実行する

  1. Visual Studio でソリューションを開きます。

  2. F5 キーを押してアプリケーションをコンパイルし、実行します。

関連項目