Re sharper能够从工作流中找到序列活动本身的源代码。在查看我的项目引用的System.Activities dll时,我看不出设计器是如何链接的。我本应该在某个地方找到一个对AttributeTableBuilder的引用,并调用AddCustomAttributes,就像用自定义设计器对活动所做的那样。
序列活动设计器的设计器源代码是否可以在互联网上找到?我希望看看它,了解微软是如何设计序列用户界面的。我试着在谷歌上搜索,但只找到了关于建立自定义活动设计师的信息。
如果您想实现与内置序列活动相同的功能,自定义活动是正确的选择,并且您应该使用WorkflowItemsPresenter,此示例将结果显示为内置序列活动:
活动设计器xaml:
<sap:ActivityDesigner x:Class="ProjectForm2.ActivityDesigner1"
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>
<Style x:Key="WorkflowItemsPresenterStyle" TargetType="sap:WorkflowItemsPresenter">
<Setter Property="SpacerTemplate">
<Setter.Value>
<DataTemplate>
<Border Background="Transparent">
<Path Data="F1M181.297,177.841L181.205,177.746 181.385,177.563 202.804,156.146 202.804,135.07 178.497,159.373 170.847,167.026 170.666,167.205 163.107,159.653 138.804,135.345 138.804,156.42 160.219,177.841 170.76,188.379 181.297,177.841z"
Stretch="Uniform" Fill="#FFDEDDDD"
Width="15" Height="15" Margin="0,0,0,0" RenderTransformOrigin="0.5,0.5"/>
</Border>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate >
<StackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
</sap:ActivityDesigner.Resources>
<Grid>
<Grid.Resources>
</Grid.Resources>
<sap:WorkflowItemsPresenter Style="{StaticResource WorkflowItemsPresenterStyle}" AllowDrop="True" Items="{Binding Path=ModelItem.Activities}" HintText="Insert here">
</sap:WorkflowItemsPresenter>
</Grid>
活动类别:
[Designer(typeof(ActivityDesigner1))]
public sealed class CodeActivity1 : CodeActivity
{
public CodeActivity1()
{
Activities = new List<Activity>();
Activities.Add(new Assign());
Activities.Add(new Assign());
}
public List<Activity> Activities { get; set; }
protected override void Execute(CodeActivityContext context)
{
}
}
设计器存在于System.Activities.Core.Presentation.dll中,如果将其添加到您使用的项目中,则可以使用Re-Sharper浏览到:System.Activities.Core.Presentation.SequenceDesigner
设计器使用DesignerMetadata类中的AtributeTableBuilder进行映射:System.Activities.Core.Presentation.Designer元数据
您还可以在以下位置查看c#代码:http://referencesource.microsoft.com/#System.Activities.Core.Presentation/System/Activities/Core/Presentation/SequenceDesigner.xaml.cs
我后来发现的一个有趣的方法是,你可以直接使用这个答案中列出的序列的设计器。
我仍然没有找到真正的XAML。。。。看到真实的东西会很有趣。