カスタム複合デザイナー - Workflow Items Presenter
このトピックの内容は、Windows Workflow Foundation 4 に該当します。
WorkflowItemsPresenter は、格納されている要素のコレクションを編集できる、WF デザイナー プログラミング モデル内の主要な型です。このサンプルでは、このような編集可能なコレクションを表示するアクティビティ デザイナーの構築方法を示します。
このサンプルでは、次の方法を示します。
WorkflowItemsPresenter を使用したカスタム アクティビティ デザイナーの作成
"折りたたまれている" および "展開されている" ビューを示すアクティビティ デザイナーの作成
再ホストされたアプリケーションでの既定のデザイナーのオーバーライド
サンプルを設定、ビルド、および実行するには
C# または VB 用の UsingWorkflowItemsPresenter.sln サンプル ソリューションを Visual Studio 2010 で開きます。
ソリューションをビルドして実行します。再ホストされたワークフロー デザイナー アプリケーションが開き、アクティビティをキャンバスにドラッグできます。
サンプルの詳細
このサンプルのコードには、次の内容が表示されます。
デザイナーをビルドするアクティビティは
Parallel
です。WorkflowItemsPresenter を使用してカスタム アクティビティ デザイナーを作成します。次の点に注意してください。
WPF データ バインドを使用して
ModelItem.Branches
にバインドする点に注目してください。ModelItem
は、デザイナーが使用されている基になっているオブジェクト (この例ではParallel
) を参照する WorkflowElementDesigner のプロパティです。SpacerTemplate は、コレクション内の個々の項目間にビジュアル表示を配置するために使用できます。
ItemsPanel は、コレクション内の項目のレイアウトを決定するために提供できるテンプレートです。この例では、水平方向のスタック パネルが使用されます。
このコード例を次に示します。
<sad:WorkflowItemsPresenter HintText="Drop Activities Here"
Items="{Binding Path=ModelItem.Branches}">
<sad:WorkflowItemsPresenter.SpacerTemplate>
<DataTemplate>
<Ellipse Width="10" Height="10" Fill="Black"/>
</DataTemplate>
</sad:WorkflowItemsPresenter.SpacerTemplate>
<sad:WorkflowItemsPresenter.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</sad:WorkflowItemsPresenter.ItemsPanel>
</sad:WorkflowItemsPresenter>
DesignerAttribute
のParallel
型への関連付けを実行し、報告された属性を出力します。- 最初に、すべての既定のデザイナーを登録します。
このコード例を次に示します。
// register metadata
(new DesignerMetadata()).Register();
RegisterCustomMetadata();
' register metadata
Dim metadata = New DesignerMetadata()
metadata.Register()
' register custom metadata
RegisterCustomMetadata()
-
- 次に、
RegisterCustomMetadata
メソッドで parallel をオーバーライドします。
- 次に、
次に、C# と Visual Basic のコード例をそれぞれ示します。
C#
void RegisterCustomMetadata()
{
AttributeTableBuilder builder = new AttributeTableBuilder();
builder.AddCustomAttributes(typeof(Parallel), new DesignerAttribute(typeof(CustomParallelDesigner)));
MetadataStore.AddAttributeTable(builder.CreateTable());
}
Sub RegisterCustomMetadata()
Dim builder As New AttributeTableBuilder()
builder.AddCustomAttributes(GetType(Parallel), New DesignerAttribute(GetType(CustomParallelDesigner)))
MetadataStore.AddAttributeTable(builder.CreateTable())
End Sub
- 最後に、さまざまなデータ テンプレートとトリガーを使用して、
IsRootDesigner
プロパティに基づいて適切なテンプレートを選択していることに注目してください。
このコード例を次に示します。
<sad:ActivityDesigner x:Class="Microsoft.Samples.CustomParallelDesigner"
xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sad="clr-namespace:System.Activities.Design;assembly=System.Activities.Design"
xmlns:sadv="clr-namespace:System.Activities.Design.View;assembly=System.Activities.Design">
<sad:ActivityDesigner.Resources>
<DataTemplate x:Key="Expanded">
<StackPanel>
<TextBlock>This is the Expanded View</TextBlock>
<sad:WorkflowItemsPresenter HintText="Drop Activities Here"
Items="{Binding Path=ModelItem.Branches}">
<sad:WorkflowItemsPresenter.SpacerTemplate>
<DataTemplate>
<Ellipse Width="10" Height="10" Fill="Black"/>
</DataTemplate>
</sad:WorkflowItemsPresenter.SpacerTemplate>
<sad:WorkflowItemsPresenter.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</sad:WorkflowItemsPresenter.ItemsPanel>
</sad:WorkflowItemsPresenter>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="Collapsed">
<TextBlock>This is the Collapsed View</TextBlock>
</DataTemplate>
<Style x:Key="ExpandOrCollapsedStyle" TargetType="{x:Type ContentPresenter}">
<Setter Property="ContentTemplate" Value="{DynamicResource Collapsed}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsRootDesigner}" Value="true">
<Setter Property="ContentTemplate" Value="{DynamicResource Expanded}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</sad: ActivityDesigner.Resources>
<Grid>
<ContentPresenter Style="{DynamicResource ExpandOrCollapsedStyle}" Content="{Binding}"/>
</Grid>
</sad: ActivityDesigner>
注 : |
---|
サンプルは、既にコンピューターにインストールされている場合があります。続行する前に、次の (既定の) ディレクトリを確認してください。
<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\WorkflowItemsPresenter
|