System.Activities.Presentation.WorkflowItemsPresenterは、含まれる要素のコレクションの編集を可能にする WF デザイナー プログラミング モデルのキー型です。 このサンプルでは、このような編集可能なコレクションを表示するアクティビティ デザイナーを構築する方法を示します。
WorkflowItemsPresenter サンプルでは、次の例を示します。
System.Activities.Presentation.WorkflowItemsPresenterを使用してカスタム アクティビティ デザイナーを作成する。
「閉じたビュー」と「展開したビュー」を使用してアクティビティデザイナーを作成する。
再ホストされたアプリケーションで既定のデザイナーをオーバーライドする。
サンプルを設定、ビルド、実行する
Visual Studio で C# または Visual Basic 用の UsingWorkflowItemsPresenter.sln サンプル ソリューションを開きます。
ソリューションをビルドして実行します。
再ホストされたワークフロー デザイナー アプリケーションが開き、キャンバスにアクティビティをドラッグできます。
サンプルの強調表示
このサンプルのコードは次のとおりです。
デザイナーが構築するアクティビティは次のとおりです。
Parallel
System.Activities.Presentation.WorkflowItemsPresenterを使用したカスタム アクティビティ デザイナーの作成。 いくつかの点を指摘する必要があります。
WPF データ バインディングを使用して
ModelItem.Branches
にバインドする方法に注意してください。ModelItem
は、デザイナーが使用されている基になるオブジェクト (この場合はWorkflowElementDesigner
) を参照するParallel
のプロパティです。WorkflowItemsPresenter.SpacerTemplateを使用して、コレクション内の個々の項目間に表示するビジュアルを配置できます。
WorkflowItemsPresenter.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
メソッドで並列をオーバーライドします。次のコードは、C# と Visual Basic でこれを示しています。
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="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://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>
こちらも参照ください
.NET