重新托管的设计器中的活动始终处于折叠状态

时间:2010-11-15 22:17:08

标签: android-activity designer workflow-foundation-4 rehosting

我正在尝试重新设计设计师,但每次我都将工作流程打到设计师手中:

_workflowDesigner = new WorkflowDesigner();
// added to UI here
Properties.Content = _workflowDesigner.PropertyInspectorView;
_workflowDesigner.Load(myWorkflowInstance);

其中myWorkflowInstance是在引用的程序集中定义的工作流程。我已经完成了魔术Register以获取注册的默认活动元数据:

new DesignerMetadata().Register();

我已经注册了所有自定义的NativeActivities:

public static void Register(IEnumerable<Type> activityTypes)
{            
    // activityTypes are all my custom NativeActivities
    // and all workflows (root of System.Activities.Activity)
    var builder = new AttributeTableBuilder();
    var attrGroups =
        from x in activityTypes
        from y in x.GetCustomAttributes(true).OfType<Attribute>()
        group y by x into g 
        select g;

    foreach (var typeGroup in attrGroups)
        builder.AddCustomAttributes(typeGroup.Key, typeGroup.ToArray());
    MetadataStore.AddAttributeTable(builder.CreateTable());
}

然而,当我在设计师中加载一个活动时,这就是我得到的:

Why r u collapsed?

我在这里缺少什么?


我认为这与这些工作流程已编译并且仅存在于Activity的Implementation属性中这一事实有关...

2 个答案:

答案 0 :(得分:1)

您的工作流实例是否包含在ActivityBuilder中?

更新: 在这里进一步研究我发现了一个使用WorkflowInspectionServices的可能解决方案。

var activities = WorkflowInspectionServices.GetActivities(new DemoWorkflow());
designer.Load(activities.First());

答案 1 :(得分:0)

一些反射和反射让我陷入了这种讽刺:

var impl = (typeof(DemoWorkflow)
            .GetProperty("Implementation", 
                         BindingFlags.NonPublic | BindingFlags.Instance)
            .GetValue(new DemoWorkflow(), new object[0]) 
            as System.Func<System.Activities.Activity>)();

_workflowDesigner.Load(new ActivityBuilder { Implementation = impl });
这是吗?真的吗?知道我写了那个,我感到恶心。脏。

我在反射器中注意到,工作流的xaml实际上嵌入在资源流的程序集中: the stream in Reflector

但是所有使用它的尝试都失败了。

var target = typeof(DemoWorkflow);
var name = string.Format("{0}.obj.Debug.{1}.g.xaml", 
                         target.Assembly.GetName().Name, 
                         target.Name);
Activity derp = null;
using (var stream = assy.Assembly.GetManifestResourceStream(name))
{
    var reader = new XamlXmlReader(stream, new XamlSchemaContext());
    // throws an exception as the property Implementation is in the xaml;
    // it is protected and cannot be set, so deserialization blows up
    derp = ActivityXamlServices.Load(reader);
}

此时我没有看到任何其他选项。