【问题标题】:Run Workflow with nested XAML-activity使用嵌套的 XAML 活动运行工作流
【发布时间】:2015-12-23 12:15:20
【问题描述】:
我需要运行工作流 XAML,但该工作流保留对其他 XAML 的引用。当我尝试通过
运行工作流时
ActivityXamlServicesSettings settings = new ActivityXamlServicesSettings
{
CompileExpressions = true
};
return ActivityXamlServices.Load(stream, settings);
我从 Load 方法得到下一个错误:
活动“MyNamespace.MyMainActivity”的 CacheMetadata 抛出“System.Xaml.XamlObjectWriterException:无法创建未知类型“{clr-namespace:MyNamespace}MyNestedActivity”。
我该如何解决?
【问题讨论】:
标签:
workflow-foundation-4
workflow-foundation
workflow-foundation-4.5
【解决方案1】:
我认为您必须将内部 xamls 转换为 dll(程序集)文件。并在读取/加载父 xaml 时加载程序集文件。
System.Xaml.XamlXmlReaderSettings xmlsettings = new System.Xaml.XamlXmlReaderSettings();
if(dllFile != null) {
Assembly wfAssembly = Assembly.Load(dllFile);
xmlsettings.LocalAssembly = wfAssembly;
}
System.IO.StringReader stringReader = new System.IO.StringReader(xaml);
XamlXmlReader reader = new XamlXmlReader(stringReader, xmlsettings);
ActivityXamlServicesSettings settings = new ActivityXamlServicesSettings { CompileExpressions = true };
Activity activity = System.Activities.XamlIntegration.ActivityXamlServices.Load(reader, settings);
希望这会有所帮助。