Xamarin.Essentials: extensiones de plataformaXamarin.Essentials: Platform Extensions

Xamarin.Essentials ofrece varios métodos de extensión de plataforma al trabajar con tipos de plataforma como Rect, Size y Point.Xamarin.Essentials provides several platform extension methods when having to work with platform types such as Rect, Size, and Point. Esto significa que puede convertir la versión System de estos tipos a tipos específicos de iOS, Android y UWP.This means that you can convert between the System version of these types for their iOS, Android, and UWP specific types.

Primeros pasosGet started

Para empezar a usar esta API, lea la guía de introducción para Xamarin.Essentials con el fin de asegurarse de que la biblioteca está correctamente instalada y configurada en los proyectos.To start using this API, read the getting started guide for Xamarin.Essentials to ensure the library is properly installed and set up in your projects.

Uso de las extensiones de plataformaUsing Platform Extensions

Agregue una referencia a Xamarin.Essentials en su clase:Add a reference to Xamarin.Essentials in your class:

using Xamarin.Essentials;

Todas las extensiones de plataforma solo se pueden llamar desde proyectos UWP, iOS o Android.All platform extensions can only be called from the iOS, Android, or UWP project.

PuntoPoint

var system = new System.Drawing.Point(x, y);

// Convert to CoreGraphics.CGPoint, Android.Graphics.Point, and Windows.Foundation.Point
var platform = system.ToPlatformSize();

// Back to System.Drawing.Size
var system2 = platform.ToSystemSize();

TamañoSize

var system = new System.Drawing.Size(width, height);

// Convert to CoreGraphics.CGSize, Android.Util.Size, and Windows.Foundation.Size
var platform = system.ToPlatformSize();

// Back to System.Drawing.Size
var system2 = platform.ToSystemSize();

RectánguloRectangle

var system = new System.Drawing.Rectangle(x, y, width, height);

// Convert to CoreGraphics.CGRect, Android.Graphics.Rect, and Windows.Foundation.Rect
var platform = system.ToPlatformSize();

// Back to System.Drawing.Size
var system2 = platform.ToSystemSize();

APIAPI