TopLevel Runtime Services SurfacePrimary app-facing APIs:
TopLevelWindowBaseWindowTopLevel.GetTopLevel(...)WindowIconWindowTransparencyLevel, WindowTransparencyLevelCollectionWindowCloseReason, WindowClosingEventArgsWindowResizeReason, WindowResizedEventArgsService entry points exposed by TopLevel:
StorageProviderClipboardLauncherScreensInsetsManagerInputPaneFocusManagerPlatformSettingsTopLevel Runtime Services SurfaceUse TopLevel.GetTopLevel(visual) at runtime, then consume host services from that surface.
var topLevel = TopLevel.GetTopLevel(this);
if (topLevel is null)
return;
var storage = topLevel.StorageProvider;
var launcher = topLevel.Launcher;
var clipboard = topLevel.Clipboard;
var screens = topLevel.Screens;
Platform/host interop helpers:
TryGetPlatformHandle()RequestPlatformInhibition(PlatformInhibitionType type, string reason)RequestAnimationFrame(Action<TimeSpan> action)Use case examples:
RequestPlatformInhibition),RequestAnimationFrame),TryGetPlatformHandle).Core TopLevel properties/events:
ClientSizeProperty, ClientSizeFrameSizeProperty, FrameSizePointerOverElementPropertyTransparencyLevelHintPropertyActualTransparencyLevelPropertyTransparencyBackgroundFallbackProperty, TransparencyBackgroundFallbackActualThemeVariantProperty, RequestedThemeVariantPropertySystemBarColorPropertyAutoSafeAreaPaddingPropertyBackRequestedEventOpened, Closed, ScalingChanged, BackRequestedRenderScalingTopLevel.PlatformImplAttached-property helpers:
SetSystemBarColor(...), GetSystemBarColor(...)SetAutoSafeAreaPadding(...), GetAutoSafeAreaPadding(...)Pattern:
if (TopLevel.GetTopLevel(this) is { } top)
{
top.TransparencyBackgroundFallback = Brushes.Black;
TopLevel.SetAutoSafeAreaPadding(this, true);
TopLevel.SetSystemBarColor(this, new SolidColorBrush(Colors.Black));
}
WindowBase : TopLevel adds window-host behavior:
IsActiveProperty, IsActiveOwnerProperty, OwnerTopmostProperty, TopmostDesktopScalingActivate()PositionChanged, Resized, Activated, DeactivatedWindowBase.PlatformImplWindow adds desktop-window semantics:
WindowClosingBehaviorSizeToContentProperty, SizeToContentExtendClientAreaToDecorationsHintPropertyExtendClientAreaChromeHintsPropertyExtendClientAreaTitleBarHeightHintPropertyIsExtendedIntoWindowDecorationsPropertyWindowDecorationMarginProperty, WindowDecorationMarginOffScreenMarginProperty, OffScreenMarginSystemDecorationsProperty, SystemDecorationsShowActivatedProperty, ShowActivatedShowInTaskbarProperty, ShowInTaskbarClosingBehaviorProperty, ClosingBehaviorWindowStateProperty, WindowStateIconProperty, IconWindowStartupLocationProperty, WindowStartupLocationCanResizeProperty, CanResizeCanMinimizeProperty, CanMinimizeCanMaximizeProperty, CanMaximizeWindowClosedEvent, WindowOpenedEventOwnedWindowsIsExtendedIntoWindowDecorationsIsDialogWindow.PlatformImplSortWindowsByZOrder(Window[] windows)Constructors frequently used by host integrations:
TopLevel(ITopLevelImpl impl)TopLevel(ITopLevelImpl impl, IAvaloniaDependencyResolver? dependencyResolver)WindowBase(IWindowBaseImpl impl)WindowBase(IWindowBaseImpl impl, IAvaloniaDependencyResolver? dependencyResolver)Window transparency metadata:
WindowTransparencyLevel static values:
NoneTransparentBlurAcrylicBlurMicaWindowTransparencyLevelCollectionWindow icon APIs:
WindowIcon(Bitmap bitmap)WindowIcon(string fileName)WindowIcon(Stream stream)Save(Stream stream)Window event argument tails:
WindowCloseReasonWindowClosingEventArgs (CloseReason, IsProgrammatic)WindowResizeReasonWindowResizedEventArgs (Reason)Pattern:
if (topLevel is Window window)
{
window.TransparencyLevelHint = new WindowTransparencyLevelCollection(new[]
{
WindowTransparencyLevel.Mica,
WindowTransparencyLevel.Blur
});
window.Closing += (_, e) =>
{
if (e.CloseReason == WindowCloseReason.OSShutdown)
return;
if (!e.IsProgrammatic && HasInFlightOperation())
e.Cancel = true;
};
window.Resized += (_, e) =>
{
if (e.Reason == WindowResizeReason.User)
PersistWindowSize(window.ClientSize);
};
}
In desktop apps, cache only short-lived references to top-level services; resolve from the active TopLevel when needed.
public async Task OpenFromWindowAsync(Window window)
{
var storage = window.StorageProvider;
var files = await storage.OpenFilePickerAsync(new FilePickerOpenOptions());
_ = files.Count;
}
When wiring in Application:
IClassicDesktopStyleApplicationLifetime.MainWindow for primary service root,Window/TopLevel instance.Clipboard/Launcher/StorageProvider.ScalingChanged and query InsetsManager as layout conditions change.RequestPlatformInhibition(...) promptly.TryGetPlatformHandle() as optional; include null-safe fallbacks.StorageProvider or Clipboard unavailable.
TopLevel.GetTopLevel(...) is non-null.RequestedThemeVariant, ActualThemeVariant, TransparencyLevelHint, and ActualTransparencyLevel together.IsActive, Topmost, Owner, and WindowState transitions.TopLevel/WindowBase surface first and keep platform specifics isolated.