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 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 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()

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

protected virtual bool OnFiles()

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

protected virtual bool OnImage()

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

protected byte[] ReadFile()

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. if unreadable.

protected Task<byte[]> ReadFileAsync()

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