Docsv3.31.0
Back to API Reference
Class

MediaInputBehavior

abstract
Inherits:InputBehavior

Base for handling received media — a clipboard paste, a drag-and-drop, or a picker selection. All three arrive the same way (check MediaContent.Source when it matters). The hook is subscribed here — subclass and override OnImage / OnFiles (or OnMedia for full control over every format) to do whatever the app needs: upload, insert an inline object, write to disk. Return true from an override to consume; otherwise it falls through to the text channels.

Remarks

File copies (a video, gif, or any file) arrive as references through OnFiles — read each with ReadFile. Inline image data arrives through OnImage. Reading can prompt the user on iOS / Android / web; the hook only fires on an actual paste / drop / pick, which is the consent the platforms expect.
protected override void OnEnable()
protected override void OnDisable()
protected virtual bool OnMedia(ref MediaContent content)

Full-control hook — inspect any format on content directly. Return true to consume. Default does nothing and lets OnFiles / OnImage run.

protected virtual bool OnFiles(string[] paths)

Override to handle file references (image / video / any file). Return true if consumed.

protected virtual bool OnImage(byte[] data, ClipboardFormat format)

Override to handle a raster image's bytes. Return true if consumed.

protected byte[] ReadFile(string fileReference)

Reads the bytes of a reference from OnFiles, resolved the way the platform requires — a path read on desktop, a content:// resolver on Android, the captured browser blob on web. null if unreadable.

protected Task<byte[]> ReadFileAsync(string fileReference)

Off-main-thread variant of ReadFile — read a dropped video or large file without blocking the frame (upload flows).