重新托管工作流设计器默认导入的命名空间
我正在尝试重新托管 WF4 工作流程设计器。在“导入”选项卡中,我希望默认导入一些命名空间。它看起来像这样:
导入的命名空间 http://imageshack.us/m/850/5383 /imports.png
经过大量研究,我发现如果你看一下,
workflowDesigner.Context.Items.GetValue<ImportedNamespaceContextItem>().ImportedNamespaces
你会看到已经导入的东西。但是,手动向该集合添加命名空间似乎没有任何效果。因此,我的问题是:如何以正确的方式将导入的命名空间添加到此列表中?或者,如何使用手动添加的命名空间导入来刷新上下文?
以下解决方案的其他信息:
为了解决此问题,我创建了所需的“全新”活动 XAML 文件,将其添加到我的项目中,将其构建操作设置为嵌入式资源及其自定义工具为空字符串。
然后,在初始化 WorkflowDesigner 的代码中,我执行以下操作:
_Wd = new WorkflowDesigner();
_Wd.Load(
XamlServices.Load(
ActivityXamlServices.CreateBuilderReader(
new XamlXmlReader(
Assembly.GetEntryAssembly().GetManifestResourceStream( "WpfApplication1.New.xaml" )
)
)
) as ActivityBuilder
);
现在我的工作流程已导入所有所需的命名空间。
I'm trying to rehost the WF4 Workflow Designer. In the "Imports" tab, I'd like to have some namespaces imported by default. It looks like this:
Imported namespaces http://imageshack.us/m/850/5383/imports.png
After a lot of research, I figured out that if you look at
workflowDesigner.Context.Items.GetValue<ImportedNamespaceContextItem>().ImportedNamespaces
you'll get to see things that are already imported. However, adding a namespace manually to this collection does not seem to have any effect. My question, therefore, is: How do I add imported namespaces to this list the right way? Or, how do I get the context to refresh using my manually added namespace imports?
Additional information to the solution below:
In order to solve this, I created my desired "clean slate" activity XAML file, added it to my project, set its Build Action to Embedded Resource and its Custom Tool to empty string.
Then, in the code that initializes my WorkflowDesigner, I do the following:
_Wd = new WorkflowDesigner();
_Wd.Load(
XamlServices.Load(
ActivityXamlServices.CreateBuilderReader(
new XamlXmlReader(
Assembly.GetEntryAssembly().GetManifestResourceStream( "WpfApplication1.New.xaml" )
)
)
) as ActivityBuilder
);
Now my work flow has all the desirable namespaces imported.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我这样做的方法不是从完全空的工作流程开始,而是创建一个包含所需导入的空模板。添加如下内容:
到 XAML 文件中的根 Activity 以导入 System.IO
The way I do this is by not starting with a completely empty workflow but creating an empty template with the required imports. Add something like:
to the root activity in the XAML file to import System.IO
您的解决方案还解决了重新托管基于流的活动的不同问题,并且我找不到建议的解决方案,因此我将其发布在这里。
症状是您在设计器主机中出现一个模式对话框,该对话框在 System.Activities.Presentation.View.ImportDesigner.OnContextChanged() 中声明空引用异常,
如果您加载的活动
原因:在
https://referencesource.microsoft.com/#System.Activities.Presentation/System.Activities.Presentation/System/Activities/Presentation/View/ImportDesigner.xaml.cs,1d24713ba95e69c5 访问 .Collection “Imports”属性引发空指针异常。可能是因为没有加载有关导入名称空间的信息。
Activity
解决方案:使用Alex 帖子中的
并将其 .Load() 到 WorkflowDesigner 实例中。 完整代码片段:
Your solution solves a different problem with rehosting stream based activities as well and there is no proposed solution that I could find, so I post this here.
The Symptom is that you get a modal dialog in your designer host, that states a null reference exception in System.Activities.Presentation.View.ImportDesigner.OnContextChanged(),
if you loaded an activity with
Cause: In
in https://referencesource.microsoft.com/#System.Activities.Presentation/System.Activities.Presentation/System/Activities/Presentation/View/ImportDesigner.xaml.cs,1d24713ba95e69c5 accessing the .Collection of the "Imports" property raises the null pointer exception. Probably because no information on imported namespaces got loaded.
Solution: Use the Activity
from Alex' post and .Load() it into the WorkflowDesigner instance.
Full code snippet: