c# – 调用GetService后,WF DesignerView为null
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – 调用GetService后,WF DesignerView为null,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2267字,纯文字阅读大概需要4分钟。
内容图文
![c# – 调用GetService后,WF DesignerView为null](/upload/InfoBanner/zyjiaocheng/818/e53d90a19f53467e850371dbcad34963.jpg)
我正在尝试在我的应用程序中启动一个新的设计器,但我收到一个错误:
DesignerView designerView = wd.Context.Services.GetService<DesignerView>();
所以designerView在这里将为null.我不知道自己错过了什么.
这是我的LoadWorkflowFromFile(string fileName)方法中的代码.
workflowFilePathName = fileName;
workflowDesignerPanel.Content = null;
WorkflowPropertyPanel.Content = null;
wd = new WorkflowDesigner();
wd.Load(workflowFilePathName);
DesignerView designerView = wd.Context.Services.GetService<DesignerView>();
designerView.WorkflowShellBarItemVisibility = ShellBarItemVisibility.Arguments
| ShellBarItemVisibility.Imports
| ShellBarItemVisibility.MiniMap
| ShellBarItemVisibility.Variables
| ShellBarItemVisibility.Zoom;
workflowDesignerPanel.Content = wd.View;
WorkflowPropertyPanel.Content = wd.PropertyInspectorView;
解决方法:
我知道回答可能有点晚,但未来可能会对其他人有所帮助.
大约一个星期前,我遇到了同样的问题.原来我试图获取DesignerView,而我仍然在包含重新托管的WorkflowDesigner的UserControl的初始化代码中.
我仍然在那里初始化了WorkflowDesigner,但是在将GetService调用移动到Loaded方法之后,它实际上返回了DesignerView:
public partial class MyDesignerControl : UserControl
{
private WorkflowDesigner wd;
private string workflowFilePathName;
protected override void OnInitialized(EventArgs e) {
base.OnInitialized();
wd = new WorkflowDesigner();
wd.Load(workflowFilePathName);
workflowDesignerPanel.Content = wd.View;
// this doesn't work here:
// var designerView = wd.Context.Services.GetService<DesignerView>();
}
private void MyDesignerControl_Loaded(object sender, RoutedEventArgs e) {
// here it works:
var designerView = wd.Context.Services.GetService<DesignerView>();
// null check, just to make sure it doesn't explode
if (designerView != null) {
designerView.WorkflowShellBarItemVisibility =
// ShellBarItemVisibility.Imports | <-- Uncomment to show again
ShellBarItemVisibility.MiniMap |
// ShellBarItemVisibility.Variables | <-- Uncomment to show again
// ShellBarItemVisibility.Arguments | <-- Uncomment to show again
ShellBarItemVisibility.Zoom;
}
}
...
}
一旦我有了DesignerView,WorkflowShellBarItemVisibility部分就按预期工作了.
(为了完整起见:不要忘记将方法注册到XAML中的相应事件):
<UserControl x:Class="My.Namespace.Here.MyDesignerControl"
...
Loaded="MyDesignerControl_Loaded">
内容总结
以上是互联网集市为您收集整理的c# – 调用GetService后,WF DesignerView为null全部内容,希望文章能够帮你解决c# – 调用GetService后,WF DesignerView为null所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。