IPlatformApplication.Current Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the current platform application instance.
public:
static property Microsoft::Maui::IPlatformApplication ^ Current { Microsoft::Maui::IPlatformApplication ^ get(); void set(Microsoft::Maui::IPlatformApplication ^ value); };
public static Microsoft.Maui.IPlatformApplication? Current { get; set; }
static member Current : Microsoft.Maui.IPlatformApplication with get, set
Public Shared Property Current As IPlatformApplication
Property Value
The current IPlatformApplication instance, or null if not set.
Examples
// Accessing a service from the platform application
var platformApp = IPlatformApplication.Current;
if (platformApp != null)
{
var myService = platformApp.Services.GetService<IMyService>();
// Use the service...
}
Remarks
This property provides access to the platform-specific application instance and its services. It must be manually set by each platform implementation during application startup.
Common usage scenarios:
- Accessing platform services:
IPlatformApplication.Current?.Services - Getting the application instance:
IPlatformApplication.Current?.Application - Platform-specific operations requiring the native application context
Always check for null before using this property, especially during application startup or in unit tests where the platform application may not be initialized.