我试图在应用程序中启动新的设计器,但在以下位置出现错误:

     DesignerView designerView = wd.Context.Services.GetService<DesignerView>();

所以designerView在这里将为空。我不知道我错过了什么。
这是loadworkflowfromfile(字符串文件名)方法中的代码。
            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,而我仍在包含重新承载的工作流设计器的usercontrol的初始化代码中。
我仍然在那里初始化了WorkflowDesigner,但是在将GetService调用移动到加载的方法之后,它实际上返回了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">

09-05 03:02