WorkflowItemPresenter是WF設計器編程模型中的關鍵類型,允許您建立一個可放置任意活動的「置放區域」。 此範例示範如何建置顯示這類「置放區域」的活動設計工具。
使用 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 上的屬性,用於指示設計工具應用的基礎物件,在此案例中為 SimpleNativeActivity。
設定、建置和執行範例
在 Visual Studio 中開啟解決方案 。
按 F5 即可編譯和執行應用程式。