开发者

Categorizing properties of XAML activities

Using a code activity (i.e. activity built out of C#) we can add category attributes to our properties and display them nicely in the property grid of the workflow designer e.g.

    [RequiredArgument]
    [Category("Input")]
    public InArgument<Guid> TermbaseId { get; set; }

Is the same functionality possible in an XAML activity?

Edit: Included XAML example: I would like to add [Category("Input")] to In and [Category("Output")] to Out in the following Xaml

<Activity mc:Ignorable="sap" x:Class="ActivityLibrary1.Activity1" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="clr-namespace:Microsoft.VisualBasic;assembly=System" xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:s1="clr-namespace:System;assembly=System" xmlns:s2="clr-namespace:System;assembly=System.Xml" xmlns:s3="clr-namespace:System;assembly=System.Core" xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities" xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=System" xmlns:scg1="clr-namespace:System.Collections.Generic;assembly=System.ServiceModel" xmlns:scg2="clr-namespace:System.Collections.Generic;assembly=System.Core" xmlns:scg3="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:sd="clr-namespace:System.Data;assembly=System.Data" xmlns:sl="clr-namespace:System.Linq;assembly=System.Core" xmlns:st="clr-namespace:System.Text;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <x:Members>
    <x:Property Name="In" Type="InArgument(x:String)" />
    <x:Property Name="Out" Type="OutArgument(x:String)" />
  </x:Members>      
<sap:VirtualizedContainerService.HintSize>240,240</sap:Virtualiz开发者_StackOverflow中文版edContainerService.HintSize>
  <mva:VisualBasic.Settings>Assembly references and imported namespaces for internal implementation</mva:VisualBasic.Settings>
</Activity>


Should be something like:

<x:Property.Attributes>
    <sc:CategoryAttribute xmlns:sc="clr-namespace:System.ComponentModel;assembly=System">
        <x:Arguments><!-- x:Arguments is the Xaml way of constructing objects which require constructor arguments -->
            <x:String>Input</x:String>
        </x:Arguments>
    </sc:CategoryAttribute>
</x:Property.Attributes>

(x:Arguments see http://msdn.microsoft.com/en-us/library/ee795382.aspx

I don't think CategoryAttribute has TypeConverter for a more compact representation, although I could be wrong...)


You can add attributes in XAML using the syntax. See the MSDN docs.


If it helps anyone else I ended up writing an automaticPropertyCategorizer to give all activities a category:

public class AutomaticPropertyCategorizer : IRegisterMetadata
{
   public void Register()
    {
        AttributeTableBuilder builder = new AttributeTableBuilder();

        foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies().
           Where(a => !a.FullName.StartsWith("System")))
        {
            var activityTypes = from t in assembly.GetTypes()
                                where t.IsSubclassOf(typeof(Activity)) 
                                select t;
            foreach (Type t in activityTypes)
            {
                foreach (PropertyDescriptor pd in properties)
                {
                    if (pd.PropertyType.IsSubclassOf(typeof(InArgument)))
                    {
                        tableBuilder.AddCustomAttributes(activityType, pd.Name, new CategoryAttribute("Input"));
                    }
                    else if (pd.PropertyType.IsSubclassOf(typeof(OutArgument)))
                    {
                        tableBuilder.AddCustomAttributes(activityType, pd.Name, new CategoryAttribute("Output"));
                    }
                    else if (pd.PropertyType.IsSubclassOf(typeof(InOutArgument)))
                    {
                         tableBuilder.AddCustomAttributes(activityType, pd.Name, new CategoryAttribute("Input / Output"));
                    }
                }
            }
        }

        AttributeTable attributes = builder.CreateTable();

        MetadataStore.AddAttributeTable(attributes);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜