Language

IImageSourcePaint Interface

Definition

Exposes the IImageSource of a Paint that .NET MAUI uses to fill an area with an image.

public interface class IImageSourcePaint
public interface IImageSourcePaint
type IImageSourcePaint = interface
Public Interface IImageSourcePaint

Remarks

This is a consumption-only contract. It exists so that code receiving a Paint - most commonly a platform backend handling Background - can recognize an image background and read its image source without reflection.

Implementing this interface outside of .NET MAUI is not supported. .NET MAUI reserves the right to add members to this interface in future releases, which would be a breaking change for external implementers. Only paints created by .NET MAUI are guaranteed to be recognized and rendered by the built-in handlers; a custom Paint implementing this interface is not guaranteed to be honored, because not every built-in handler routes backgrounds through the image-source path.

Values implementing this interface are obtained by pattern matching an existing Paint, typically from Background. In .NET MAUI a paint of this kind is produced when a background is set from an image - for example a Microsoft.Maui.Controls.ImageBrush, or Page.BackgroundImageSource.

ImageSource can be null, which represents an image background with nothing to draw. Treat it the same as having no image background: clear any previously applied image rather than attempting to resolve it. A non-null value should be resolved through an IImageSourceServiceProvider; note that resolution is asynchronous and may still yield no image.

This is distinct from ImagePaint. ImagePaint carries an already-loaded IImage for drawing operations, whereas this contract carries an unresolved IImageSource that describes where an image comes from (a file, URI, stream, or font glyph) and must be loaded through an image source service. A paint will not implement both.

The following example shows how a platform backend can render an image background:
public static void MapBackground(IViewHandler handler, IView view)
{
    if (view.Background is IImageSourcePaint imagePaint)
    {
        // May be null, in which case any existing image background is cleared.
        var provider = handler.GetRequiredService<IImageSourceServiceProvider>();
        ApplyImageBackgroundAsync(handler.PlatformView, imagePaint.ImageSource, provider);
    }
    else
    {
        ApplyPaintBackground(handler.PlatformView, view.Background);
    }
}

Properties

Name Description
ImageSource

Gets the image source used to fill the area, or null when there is no image to draw.

Applies to