In This Article

Image Source Providers

Image source providers are classes that provide ImageSource objects on demand to IntelliPrompt sessions. An example of their usage is providing image sources for completion list items.

The IImageSourceProvider Interface

All image source providers implement the IImageSourceProvider interface. There are a couple built-in provider implementations described below.

The DirectImageSourceProvider Class

The DirectImageSourceProvider is the simplest way to provide image sources. Its constructor takes an ImageSource instance and that is what is returned by the provider.

The downside to using this provider is that the image source must be loaded prior to creation of the provider. If a large number of providers are needed (such as for a completion list), then it is better to use another provider or build a custom one.

This code creates a DirectImageSourceProvider using the ImageSource that is already loaded in a source variable:

DirectImageSourceProvider provider = new DirectImageSourceProvider(source);

The CommonImageSourceProvider Class

The CommonImageSourceProvider is a handy image source provider that comes pre-packaged with some of the most common 16x16 icons used in features like completion lists.

Its constructor takes a single parameter of type CommonImageKind, which is an enumeration that specifies one of many built-in images. This image source provider works on-demand and only pulls the image from assembly resources as needed.

This code creates a CommonImageSourceProvider that returns a 16x16 public method icon:

CommonImageSourceProvider provider = new CommonImageSourceProvider(CommonImageKind.MethodPublic);

Image Set Selection

There are several image sets that are included with SyntaxEditor:

  • Classic - Best for non-Metro themes.
  • MetroLight (default) - Best for most Metro themes.
  • MetroDark - Best for the MetroDark theme.
Tip

The MetroLight and MetroDark image sets are implemented with vector graphics, enabling the best clarity when used on high DPI systems.

To change the image set that is currently in effect, set the CommonImageSourceProvider.DefaultImageSet property to a CommonImageSet value. Note that some UI, such as for the NavigableSymbolSelector, may need to be reloaded following a change to this property.

// Configure image set for dark theme
CommonImageSourceProvider.DefaultImageSet = CommonImageSet.MetroDark;

Custom Image Source Providers

It's easy to write your own custom image source provider if none of the implementations above work for your scenario. Simply create a class that implements IImageSourceProvider.

The GetImageSource method that must be implemented as part of that interface returns an ImageSource object. You could have it be pulled from a resource, database, or any other storage mechanism.

Since the method is called on-demand, the image source doesn't need to be loaded up front.