Window Surface and Decoration APIsWindowBase Integration APIsTopLevel Bridge APIsPrimary app-building APIs:
Window, WindowBase, TopLevelSystemDecorations, SizeToContent, WindowClosingBehaviorWindowTransparencyLevel, WindowTransparencyLevelCollectionExtendClientAreaToDecorationsHint, ExtendClientAreaChromeHints, ExtendClientAreaTitleBarHeightHintWindow.BeginMoveDrag(...), Window.BeginResizeDrag(...)Window.WindowDecorationMargin, Window.OffScreenMarginWindowIconWindowCloseReason, WindowClosingEventArgsWindowResizeReason, WindowResizedEventArgsRelated platform-facing interfaces (mostly backend-level):
ITopLevelImplIWindowBaseImplIWindowImplIWindowingPlatformFor service access from top-level surfaces (StorageProvider, Clipboard, Launcher, Screens, platform handle), see:
Window Surface and Decoration APIsKey Window properties/events for custom chrome and host behavior:
SizeToContentProperty, SizeToContentExtendClientAreaChromeHintsProperty, ExtendClientAreaChromeHintsWindowDecorationMarginProperty, WindowDecorationMarginOffScreenMarginProperty, OffScreenMarginSystemDecorationsProperty, SystemDecorationsClosingBehaviorProperty, ClosingBehaviorWindowStateProperty, WindowStateIconProperty, IconWindowStartupLocationProperty, WindowStartupLocationOwnedWindowsIsExtendedIntoWindowDecorationsIsDialogClosingLifecycle and ordering helpers:
Show(), Show(owner), ShowDialog(owner), ShowDialog<TResult>(owner)Hide(), Close(), Close(dialogResult)SortWindowsByZOrder(Window[] windows)Platform access:
Window.PlatformImplWindowBase Integration APIsUseful WindowBase APIs for host-level coordination:
OwnerProperty, OwnerIsActiveTopmostDesktopScalingActivate()PositionChanged, Resized, Activated, DeactivatedWindowBase.PlatformImplUse WindowBase events when writing shared behaviors that apply to normal windows and derived host surfaces.
TopLevel Bridge APIsWindowBase : TopLevel, so decoration code is often coupled with these shared members:
ClientSizeProperty, ClientSizeFrameSizeProperty, FrameSizePointerOverElementPropertyTransparencyLevelHintPropertyActualTransparencyLevelPropertyTransparencyBackgroundFallbackProperty, TransparencyBackgroundFallbackSystemBarColorProperty, SetSystemBarColor(...), GetSystemBarColor(...)SetAutoSafeAreaPadding(...), GetAutoSafeAreaPadding(...)RenderScalingOpened, ScalingChanged, BackRequestedTopLevel.PlatformImpl, TryGetPlatformHandle()To build custom title bars/chrome:
ExtendClientAreaToDecorationsHint="True".ExtendClientAreaChromeHints.SystemDecorations as needed.Example:
<Window x:Class="MyApp.MainWindow"
ExtendClientAreaToDecorationsHint="True"
ExtendClientAreaChromeHints="PreferSystemChrome"
ExtendClientAreaTitleBarHeightHint="32"
SystemDecorations="Full" />
For custom drag handles:
private void TitlePointerPressed(object? sender, PointerPressedEventArgs e)
{
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
BeginMoveDrag(e);
}
For custom resize grips:
private void ResizeGripPressed(object? sender, PointerPressedEventArgs e)
{
BeginResizeDrag(WindowEdge.SouthEast, e);
}
Built-in managed decoration controls:
Avalonia.Controls.Chrome.TitleBarAvalonia.Controls.Chrome.CaptionButtonsTransparency APIs:
WindowTransparencyLevel (record struct)WindowTransparencyLevel.NoneWindowTransparencyLevel.TransparentWindowTransparencyLevel.BlurWindowTransparencyLevel.AcrylicBlurWindowTransparencyLevel.MicaWindowTransparencyLevelCollectionExample transparency hint ordering:
TransparencyLevelHint = new WindowTransparencyLevelCollection(new[]
{
WindowTransparencyLevel.Mica,
WindowTransparencyLevel.AcrylicBlur,
WindowTransparencyLevel.Blur,
WindowTransparencyLevel.Transparent,
WindowTransparencyLevel.None
});
Window icon APIs:
WindowIcon(Bitmap bitmap)WindowIcon(string fileName)WindowIcon(Stream stream)Save(Stream stream)Example:
using var iconStream = File.OpenRead("Assets/app-icon.ico");
Icon = new WindowIcon(iconStream);
using var outStream = File.Create("Assets/icon-copy.ico");
Icon?.Save(outStream);
Closing and resize event argument types:
WindowCloseReasonWindowClosingEventArgs
CloseReasonIsProgrammaticWindowResizeReasonWindowResizedEventArgs
ReasonExample:
Closing += (_, e) =>
{
if (e.CloseReason == WindowCloseReason.ApplicationShutdown)
return;
if (!e.IsProgrammatic && HasUnsavedChanges())
e.Cancel = true;
};
Resized += (_, e) =>
{
if (e.Reason == WindowResizeReason.DpiChange)
RecomputeDpiSensitiveLayout();
};
Platform extension APIs for deeper control:
Win32Properties
AddWindowStylesCallbackAddWndProcHookCallbackNonClientHitTestResultPropertyX11Properties
NetWmWindowTypePropertyWmClassPropertyUse these only when cross-platform Window/TopLevel APIs are insufficient.
Window/WindowBase APIs first.WindowDecorationMargin and OffScreenMargin in layout/pointer hit regions.PlatformImpl as an escape hatch, not baseline app code.BeginMoveDrag with left button pressed.CanResize=true and call BeginResizeDrag with correct WindowEdge.WindowDecorationMargin/OffScreenMargin to compensate.ClosingBehavior (OwnerAndChildWindows vs OwnerWindowOnly).