繁体   English   中英

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

[英]Run Workflow with nested XAML-activity

我需要运行工作流程XAML,但是该工作流程会保留对其他XAML的引用。 当我尝试通过以下方式运行工作流程时

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

我从加载方法中得到下一个错误:

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

我该如何解决?

我认为您必须将内部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);

希望这可以帮助。

暂无
暂无

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

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