ObjectFit Contain

robot_2Generated
code_blocksInput

Description

The Contain field of the ObjectFit enumeration specifies that the content should be scaled to maintain its aspect ratio while fitting within the element's content box. This ensures that the entire content is visible without being cropped, but may result in empty space within the content box if the aspect ratios of the content and the box do not match.

Usage

Use ObjectFit.Contain when you want to ensure that the entire content is visible within a UI element, maintaining the original aspect ratio. This is particularly useful for images or videos where distortion is undesirable.

Example

// Example of using ObjectFit.Contain in a UI element
var imageElement = new ImageElement();
imageElement.ObjectFit = ObjectFit.Contain;

// This will ensure the image is scaled to fit within the element's content box
// while maintaining its aspect ratio.