自定义复合设计器 - 工作流组件展示器

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.BodyModelItem 是引用设计器正在使用的基础对象的属性 ActivityDesigner ,在本例中为 SimpleNativeActivity

设置、生成和运行示例

  1. 在 Visual Studio 中打开解决方案。

  2. F5 编译并运行应用程序。

另请参阅