4.05 Icons (R7)

Skip to end of metadata
Go to start of metadata

In order to use icons in your plugin (e.g., for gutter marks), your icons need to specify them in a way that helps ReSharper render the icons and theme them if necessary. This is typically specified by a mapping from an IconId type that identifies a themable icon to an ImageSource.

Using Existing Icons

To use an existing icon (i.e., an icon that is included in ReSharper), simply pick one of the statically compiled icon classes (inheritors of CompiledIconClass) and use their Id field. For example:

The above code addresses an (autogenerated) identifier for a themed resource. Depending on the context, this resource could also be used:

  • As an image in XAML:
  • In a C# type attribute:
  • To acquire an icon in one of many possible formats (as per various GetIconXxx() methods):

Icon Conversion

The ReSharper SDK comes with different MSBuild actions that can help generate compiled icons and associated IconId's from a PNG or XAML file. In order to use it, you need to:

  • Unload your plugin project and add the following Import directive at the end of the csproj file, just before the closing </Projects> tag:
  • Reload the project.
  • Add one of the following to your project.
    • A PNG icon (typically square, e.g., 16×16 pixels in size)
    • A XAML file containing one or more DrawingBrush definitions containing the icon drawings
  • Set the icon’s build action to ThemedIconPng or ThemedIconsXamlV3
  • Compile the project.

The end result is a generated C# file (with a .Generated.cs extension) which contains icon definitions usable as described above. In the case of PNG files, a XAML file is also generated containing a string-encoded definition of the processed PNG file.

The SamplePlugin included in the ReSharper SDK demonstrates the use of the ThemedIconPng build action.