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>
WPF データ バインディングを使用して ModelItem.Body
にバインドする方法に注意してください。
ModelItem
は、デザイナーが使用されている基になるオブジェクト (この場合は ActivityDesigner) を参照するのプロパティです。
サンプルを設定、ビルド、実行する
Visual Studio でソリューションを開きます。
F5 キーを押して、アプリケーションをコンパイルして実行します。
こちらも参照ください
.NET