Description
The Contain
field of the LengthUnit
enum is used to specify that a background image should be contained within the bounds of an element. This means the image will be scaled to fit within the element's dimensions while maintaining its aspect ratio, ensuring that the entire image is visible without being cropped.
Usage
Use LengthUnit.Contain
when you want a background image to fit within an element without cropping, while maintaining the image's original aspect ratio. This is particularly useful for responsive designs where the element size may change based on the viewport or other dynamic factors.
Example
// Example of using LengthUnit.Contain in a UI element
var backgroundStyle = new Style();
backgroundStyle.BackgroundSize = LengthUnit.Contain;
var panel = new Panel();
panel.Style = backgroundStyle;
// This will ensure the background image is contained within the panel's bounds.