【问题标题】:Open a WPF window app form VS extension command打开 WPF 窗口应用程序表单 VS 扩展命令
【发布时间】:2016-04-27 10:07:51
【问题描述】:

我正在编写我的第一个 VS 扩展。 到目前为止,我有获取选定文本并显示消息框或操作选择的代码:

扩展的 CTOR..

        private StringRefactor(Package package)
        {
            if (package == null)
            {
                throw new ArgumentNullException("package");
            }

            this.package = package;

            OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
            if (commandService != null)
            {
                var menuCommandID = new CommandID(CommandSet, CommandId);
                var menuItem = new MenuCommand(this.MenuItemCallback, menuCommandID);
                commandService.AddCommand(menuItem);
            }
        }

回调:

    private void MenuItemCallback(object sender, EventArgs e)
    {
        var selection = getSelection();

        var selectedText = selection == null ? "No text selected..." : selection.StreamSelectionSpan.GetText();
        string message = string.Format(CultureInfo.CurrentCulture, "Inside {0}.MenuItemCallback()", this.GetType().FullName);
        string title = "StringRefactor";

        // Show a message box to prove we were here
        VsShellUtilities.ShowMessageBox(
            this.ServiceProvider,
            selectedText,
            title,
            OLEMSGICON.OLEMSGICON_INFO,
            OLEMSGBUTTON.OLEMSGBUTTON_OK,
            OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
    }

现在我想打开一个提示窗口,而不是VsShellUtilities.ShowMessageBox(...,它显示几个文本框和确定\取消按钮..

我想创建另一个 WPF 应用程序项目并从回调中启动它,但我不确定这是编写打开自定义工具的扩展的正确方法..

那么打开具有 VISIX 功能的自定义窗口的正确方法是什么?

【问题讨论】:

    标签: c# wpf visual-studio-extensions


    【解决方案1】:

    您可以在 VSIX 扩展中创建自己的 WPF 对话框。事实上,Visual Studio 就是为此而设计的(因为 UI 是 WPF)。

    有关更多说明,请参阅本文:

    Creating and Managing Modal Dialog Boxes

    【讨论】:

      猜你喜欢
      • 2018-03-19
      • 2022-06-16
      • 2013-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-28
      • 1970-01-01
      相关资源
      最近更新 更多