简体   繁体   English

使用嵌套的XAML活动运行工作流

[英]Run Workflow with nested XAML-activity

I need to run workflow XAML, but that workflow keeps references to other XAMLs. 我需要运行工作流程XAML,但是该工作流程会保留对其他XAML的引用。 When I'm trying to run the workflow by 当我尝试通过以下方式运行工作流程时

ActivityXamlServicesSettings settings = new ActivityXamlServicesSettings
{
    CompileExpressions = true
};
return ActivityXamlServices.Load(stream, settings);

I get next error from Load method: 我从加载方法中得到下一个错误:

CacheMetadata for activity 'MyNamespace.MyMainActivity' threw 'System.Xaml.XamlObjectWriterException: Cannot create unknown type '{clr-namespace:MyNamespace}MyNestedActivity'. 活动'MyNamespace.MyMainActivity'的CacheMetadata抛出'System.Xaml.XamlObjectWriterException:无法创建未知类型'{clr-namespace:MyNamespace} MyNestedActivity'。

How can I solve it? 我该如何解决?

I think you have to convert your internal xamls to dll (assembly) file. 我认为您必须将内部xamls转换为dll(汇编)文件。 And load the assembly file while reading/loading the parent xaml. 并在读取/加载父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);

hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM