Xamarin.Essentials: Platform Extensions
Xamarin.Essentials provides several platform extension methods when having to work with platform types such as Rect, Size, and Point. This means that you can convert between the
System version of these types for their iOS, Android, and UWP specific types.
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.
Using Platform Extensions
Add a reference to Xamarin.Essentials in your class:
All platform extensions can only be called from the iOS, Android, or UWP project.
var system = new System.Drawing.Point(x, y); // Convert to CoreGraphics.CGPoint, Android.Graphics.Point, and Windows.Foundation.Point var platform = system.ToPlatformPoint(); // Back to System.Drawing.Size var system2 = platform.ToSystemPoint();
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();
var system = new System.Drawing.Rectangle(x, y, width, height); // Convert to CoreGraphics.CGRect, Android.Graphics.Rect, and Windows.Foundation.Rect var platform = system.ToPlatformRectangle(); // Back to System.Drawing.Size var system2 = platform.ToSystemRectangle();