このトピックの内容は、Windows Workflow Foundation 4 に該当します。
WorkflowItemPresenter は、任意のアクティビティを配置できる "ドロップ ゾーン" を作成できる、WF デザイナー プログラミング モデル内の主要な型です。このサンプルでは、このような "ドロップ ゾーン" を表示するアクティビティ デザイナーの構築方法を示します。
このサンプルでは、次の方法を示します。
使用例
WorkflowItemPresenter を使用したカスタム アクティビティ デザイナーの作成
メタデータ ストアを使用したカスタム デザイナーの登録。
宣言および命令による再ホストされたツールボックスのプログラミング。
サンプルの詳細
このサンプルのコードを次に示します。
カスタム アクティビティ デザイナーは
SimpleNativeActivityクラス用に作成されます。WorkflowItemPresenter を使用してカスタム アクティビティ デザイナーを作成します。
<sap:ActivityDesigner x:Class="Microsoft.Samples.UsingWorkflowItemPresenter.SimpleNativeDesigner"
xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="https://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>
WPF データ バインドを使用して ModelItem.Body にバインドする点に注目してください。ModelItem は、デザイナーが使用されている基になっているオブジェクト (この例では SimpleNativeActivity) を参照する WorkflowElementDesigner のプロパティです。
サンプルをセットアップ、作成、および実行するには
Visual Studio 2010 で、ソリューションを開きます。
F5 キーを押してアプリケーションをコンパイルし、実行します。
注 : |
|---|
サンプルは、既にコンピューターにインストールされている場合があります。続行する前に、次の (既定の) ディレクトリを確認してください。
<InstallDrive>:\WF_WCF_Samples
このディレクトリが存在しない場合は、「.NET Framework 4 向けの Windows Communication Foundation (WCF) および Windows Workflow Foundation (WF) のサンプル」にアクセスして、Windows Communication Foundation (WCF) および WF のサンプルをすべてダウンロードしてください。このサンプルは、次のディレクトリに格納されます。
<InstallDrive>:\WF_WCF_Samples\WF\Basic\CustomActivities\CustomActivityDesigners\WorkflowItemPresenter
|
注 :