重新安置的设计师总是崩溃的活动
-
10-10-2019 - |
题
我正在尝试重新主持设计师,但是每次我将工作流打入设计师时:
_workflowDesigner = new WorkflowDesigner();
// added to UI here
Properties.Content = _workflowDesigner.PropertyInspectorView;
_workflowDesigner.Load(myWorkflowInstance);
在哪里 myWorkflowInstance
是引用组件中定义的工作流程。我做了魔术 Register
要获取默认活动元数据注册:
new DesignerMetadata().Register();
而且我已经注册了所有自定义的本质活性:
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());
}
但是,当我在设计师中加载一项活动时,这就是我得到的:
我在这里想念什么?
我认为这与这些工作流是编译,仅存在于活动的实现属性中的事实有关...
解决方案
您的工作流实例是否包裹在ActivityBuilder中?
更新:在这里进行一些调查,我发现了使用WorkFlowInspectionservices的一种可能的解决方案。
var activities = WorkflowInspectionServices.GetActivities(new DemoWorkflow());
designer.Load(activities.First());
其他提示
有点反射镜和反射使我陷入了这种危险:
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实际上嵌入了资源流中的组件中:
但是所有尝试使用此操作的尝试都失败了。
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);
}
我目前没有其他选择。
不隶属于 StackOverflow