visual-studio-2010 - Visual Studio 编辑器扩展选项对话框

标签 visual-studio-2010 mef visual-studio-extensions

我有一个简单的 Visual Studio 扩展,它的构建方式与 this walkthrough 中提供的类似。 (使用 IWpfTextViewCreationListener 接口(interface))。

该扩展程序使用了两种我想配置的颜色。

如何为此扩展定义选项对话框? (例如,出现在“工具/选项”菜单中的属性页面)

我尝试使用 DialogPage Class 来做到这一点,但显然它需要一个 VSPackage 并且我不确定这种方法是否与我正在做的兼容。

最佳答案

我认为您可以在不提供自定义 OptionsPage 的情况下自定义颜色。
您可以导出自己的颜色,它们将从工具-选项-字体和颜色中进行配置

通过您的链接示例:

[Export(typeof(EditorFormatDefinition))]
[Name("EditorFormatDefinition/MyCustomFormatDefinition")]
[UserVisible(true)]
internal class CustomFormatDefinition : EditorFormatDefinition
{
  public CustomFormatDefinition( )
  {
    this.BackgroundColor = Colors.LightPink;
    this.ForegroundColor = Colors.DarkBlue;
    this.DisplayName = "My Cusotum Editor Format";
  }
}

[Export(typeof(EditorFormatDefinition))]
[Name("EditorFormatDefinition/MyCustomFormatDefinition2")]
[UserVisible(true)]
internal class CustomFormatDefinition2 : EditorFormatDefinition
{
  public CustomFormatDefinition2( )
  {
    this.BackgroundColor = Colors.DeepPink;
    this.ForegroundColor = Colors.DarkBlue;
    this.DisplayName = "My Cusotum Editor Format 2";
  }
}

[Export(typeof(IWpfTextViewCreationListener))]
[ContentType("text")]
[TextViewRole(PredefinedTextViewRoles.Document)]
internal class TestViewCreationListener : IWpfTextViewCreationListener
{
  [Import]
  internal IEditorFormatMapService FormatMapService = null;

  public void TextViewCreated( IWpfTextView textView )
  {
    IEditorFormatMap formatMap = FormatMapService.GetEditorFormatMap(textView);

    ResourceDictionary selectedText = formatMap.GetProperties("Selected Text");
    ResourceDictionary inactiveSelectedText = formatMap.GetProperties("Inactive Selected Text");

    ResourceDictionary myCustom = formatMap.GetProperties("EditorFormatDefinition/MyCustomFormatDefinition");
    ResourceDictionary myCustom2 = formatMap.GetProperties("EditorFormatDefinition/MyCustomFormatDefinition2");

    formatMap.BeginBatchUpdate();

    selectedText[EditorFormatDefinition.BackgroundBrushId] = myCustom[EditorFormatDefinition.BackgroundBrushId];
    formatMap.SetProperties("Selected Text", selectedText);

    inactiveSelectedText[EditorFormatDefinition.BackgroundBrushId] = myCustom2[EditorFormatDefinition.BackgroundBrushId];
    formatMap.SetProperties("Inactive Selected Text", myCustom2);

    formatMap.EndBatchUpdate();
  }
}

定制 EFD 可提供 SolidColorBrush es。

如果这还不够,您还可以访问 VSPackages 使用的服务提供程序。您可以为选项页面制作一个包,并通过服务提供者使用自定义服务与编辑器扩展进行通信。

您可以像这样导入服务提供者:
[Import]
internal SVsServiceProvider serviceProvider = null;

此解决方案也不需要您迁移原始逻辑,只需要创建一个额外的包。

关于visual-studio-2010 - Visual Studio 编辑器扩展选项对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11433411/

相关文章:

visual-studio-2010 - 我仍可以在Visual Studio 2010中定位.NET Framework 1.1吗?

asp.net-mvc-3 - 我能否使用 Razor Intellisense 查看 .html 文件,就好像它们是 Visual Studio 2010 中的 .cshtml 文件一样?

c++ - 在 VC++ 2010 中使用 MSBuild 对文件进行自定义预处理

asp.net - 使用使用它们的 Web 项目部署 MEF 组件

.net - 如何在没有导出属性的情况下在 MEF 中导出类型? (例如以编程方式)

visual-studio - Visual Studio 扩展包 - 自定义文件类型 - 编辑器和图标

visual-studio-2010 - 如何使用 Visual C++ 2010 Express 从 32 位环境为 64 位 Windows 编译 Qt?

c# - 难倒在 MVC MEF 应用程序上

c# - Visual Studio 2010 C# 单行编译器

c# - 需要检测 ITextView 中显示的行是否发生变化