Class TopLevel
Base class for top-level widgets.
[TemplatePart("PART_TransparencyFallback", typeof(Border))]
public abstract class TopLevel : ContentControl, INotifyPropertyChanged, IDataContextProvider, IThemeVariantHost, IResourceHost, IResourceNode, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, IStyleable, INamed, IDataTemplateHost, ISetterValue, ILayoutRoot, IRenderRoot, ICloseable, IStyleHost, ILogicalRoot, ILogical, ITextInputMethodRoot, IInputRoot, IInputElement
- Inheritance
-
TopLevel
- Implements
- Derived
- Inherited Members
- Extension Methods
Remarks
This class acts as a base for top level widget. It handles scheduling layout, styling and rendering as well as tracking the widget's ClientSize.
Constructors
TopLevel(ITopLevelImpl)
Initializes a new instance of the TopLevel class.
public TopLevel(ITopLevelImpl impl)
Parameters
impl
ITopLevelImplThe platform-specific window implementation.
TopLevel(ITopLevelImpl, IAvaloniaDependencyResolver?)
Initializes a new instance of the TopLevel class.
public TopLevel(ITopLevelImpl impl, IAvaloniaDependencyResolver? dependencyResolver)
Parameters
impl
ITopLevelImplThe platform-specific window implementation.
dependencyResolver
IAvaloniaDependencyResolverThe dependency resolver to use. If null the default dependency resolver will be used.
Fields
ActualThemeVariantProperty
public static readonly StyledProperty<ThemeVariant> ActualThemeVariantProperty
Field Value
ActualTransparencyLevelProperty
Defines the ActualTransparencyLevel property.
public static readonly DirectProperty<TopLevel, WindowTransparencyLevel> ActualTransparencyLevelProperty
Field Value
AutoSafeAreaPaddingProperty
Defines the AutoSafeAreaPadding attached property.
public static readonly AttachedProperty<bool> AutoSafeAreaPaddingProperty
Field Value
BackRequestedEvent
Defines the BackRequested event.
public static readonly RoutedEvent<RoutedEventArgs> BackRequestedEvent
Field Value
ClientSizeProperty
Defines the ClientSize property.
public static readonly DirectProperty<TopLevel, Size> ClientSizeProperty
Field Value
FrameSizeProperty
Defines the FrameSize property.
public static readonly DirectProperty<TopLevel, Size?> FrameSizeProperty
Field Value
PointerOverElementProperty
Defines the PointerOverElement property.
public static readonly StyledProperty<IInputElement?> PointerOverElementProperty
Field Value
RequestedThemeVariantProperty
public static readonly StyledProperty<ThemeVariant?> RequestedThemeVariantProperty
Field Value
SystemBarColorProperty
Defines the SystemBarColor attached property.
public static readonly AttachedProperty<SolidColorBrush?> SystemBarColorProperty
Field Value
TransparencyBackgroundFallbackProperty
Defines the TransparencyBackgroundFallback property.
public static readonly StyledProperty<IBrush> TransparencyBackgroundFallbackProperty
Field Value
TransparencyLevelHintProperty
Defines the TransparencyLevelHint property.
public static readonly StyledProperty<IReadOnlyList<WindowTransparencyLevel>> TransparencyLevelHintProperty
Field Value
Properties
ActualTransparencyLevel
Gets the achieved WindowTransparencyLevel that the platform was able to provide.
public WindowTransparencyLevel ActualTransparencyLevel { get; }
Property Value
BypassFlowDirectionPolicies
Gets a value indicating whether control bypass FlowDirecton policies.
protected override bool BypassFlowDirectionPolicies { get; }
Property Value
Remarks
Related to FlowDirection system and returns false as default, so if FlowDirection is RTL then control will get a mirror presentation. For controls that want to avoid this behavior, override this property and return true.
ClientSize
Gets or sets the client size of the window.
public Size ClientSize { get; protected set; }
Property Value
Clipboard
Gets the platform's clipboard implementation
public IClipboard? Clipboard { get; }
Property Value
FocusManager
Gets focus manager of the root.
public IFocusManager? FocusManager { get; }
Property Value
Remarks
Focus manager can be null only if window wasn't initialized yet.
FrameSize
Gets or sets the total size of the window.
public Size? FrameSize { get; protected set; }
Property Value
- Size?
InputPane
public IInputPane? InputPane { get; }
Property Value
InsetsManager
public IInsetsManager? InsetsManager { get; }
Property Value
Launcher
public ILauncher Launcher { get; }
Property Value
PlatformImpl
Gets the platform-specific window implementation.
public ITopLevelImpl? PlatformImpl { get; }
Property Value
PlatformSettings
Represents a contract for accessing top-level platform-specific settings.
public IPlatformSettings? PlatformSettings { get; }
Property Value
Remarks
PlatformSettings can be null only if window wasn't initialized yet.
RenderScaling
The scaling factor to use in rendering.
public double RenderScaling { get; }
Property Value
RendererDiagnostics
Gets a value indicating whether the renderer should draw specific diagnostics.
public RendererDiagnostics RendererDiagnostics { get; }
Property Value
RequestedThemeVariant
Gets or sets the UI theme variant that is used by the control (and its child elements) for resource determination. The UI theme you specify with ThemeVariant can override the app-level ThemeVariant.
public ThemeVariant? RequestedThemeVariant { get; set; }
Property Value
Remarks
Setting RequestedThemeVariant to Default will apply parent's actual theme variant on the current scope.
Screens
Gets platform screens implementation.
public Screens? Screens { get; }
Property Value
StorageProvider
File System storage service used for file pickers and bookmarks.
public IStorageProvider StorageProvider { get; }
Property Value
TransparencyBackgroundFallback
Gets or sets the IBrush that transparency will blend with when transparency is not supported. By default this is a solid white brush.
public IBrush TransparencyBackgroundFallback { get; set; }
Property Value
TransparencyLevelHint
Gets or sets the WindowTransparencyLevel that the TopLevel should use when possible. Accepts multiple values which are applied in a fallback order. For instance, with "Mica, Blur" Mica will be applied only on platforms where it is possible, and Blur will be used on the rest of them. Default value is an empty array or "None".
public IReadOnlyList<WindowTransparencyLevel> TransparencyLevelHint { get; set; }
Property Value
Methods
GetAutoSafeAreaPadding(Control)
Gets if auto safe area padding is enabled.
public static bool GetAutoSafeAreaPadding(Control control)
Parameters
control
ControlThe main view attached to the toplevel, or the toplevel.
Returns
GetSystemBarColor(Control)
Helper for getting the color of the platform's system bars.
public static SolidColorBrush? GetSystemBarColor(Control control)
Parameters
control
ControlThe main view attached to the toplevel, or the toplevel.
Returns
- SolidColorBrush
The current color of the platform's system bars.
GetTopLevel(Visual?)
public static TopLevel? GetTopLevel(Visual? visual)
Parameters
visual
VisualThe visual to query its TopLevel
Returns
- TopLevel
The TopLevel
InvalidateMirrorTransform()
Computes the HasMirrorTransform value according to the FlowDirection and BypassFlowDirectionPolicies
protected override void InvalidateMirrorTransform()
OnApplyTemplate(TemplateAppliedEventArgs)
Called when the control's template is applied. In simple terms, this means the method is called just before the control is displayed.
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
Parameters
e
TemplateAppliedEventArgsThe event args.
OnAttachedToVisualTree(VisualTreeAttachmentEventArgs)
Called when the control is added to a rooted visual tree.
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
Parameters
e
VisualTreeAttachmentEventArgsThe event args.
OnClosed(EventArgs)
Raises the Closed event.
protected virtual void OnClosed(EventArgs e)
Parameters
e
EventArgsThe event args.
OnOpened(EventArgs)
Raises the Opened event.
protected virtual void OnOpened(EventArgs e)
Parameters
e
EventArgsThe event args.
OnPropertyChanged(AvaloniaPropertyChangedEventArgs)
Called when a avalonia property changes on the object.
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
Parameters
change
AvaloniaPropertyChangedEventArgsThe property change details.
RequestAnimationFrame(Action<TimeSpan>)
Enqueues a callback to be called on the next animation tick
public void RequestAnimationFrame(Action<TimeSpan> action)
Parameters
RequestPlatformInhibition(PlatformInhibitionType, string)
Requests a PlatformInhibitionType to be inhibited. The behavior remains inhibited until the return value is disposed. The available set of PlatformInhibitionTypes depends on the platform. If a behavior is inhibited on a platform where this type is not supported the request will have no effect.
public Task<IDisposable> RequestPlatformInhibition(PlatformInhibitionType type, string reason)
Parameters
type
PlatformInhibitionTypereason
string
Returns
SetAutoSafeAreaPadding(Control, bool)
Enabled or disables whenever TopLevel should automatically adjust paddings depending on the safe area.
public static void SetAutoSafeAreaPadding(Control control, bool value)
Parameters
control
ControlThe main view attached to the toplevel, or the toplevel.
value
boolValue to be set.
SetSystemBarColor(Control, SolidColorBrush?)
Helper for setting the color of the platform's system bars.
public static void SetSystemBarColor(Control control, SolidColorBrush? color)
Parameters
control
ControlThe main view attached to the toplevel, or the toplevel.
color
SolidColorBrushThe color to set.
StartRendering()
protected void StartRendering()
StopRendering()
protected void StopRendering()
TryGetPlatformHandle()
Trys to get the platform handle for the TopLevel-derived control.
public IPlatformHandle? TryGetPlatformHandle()
Returns
- IPlatformHandle
An IPlatformHandle describing the window handle, or null if the handle could not be retrieved.
Events
BackRequested
Occurs when physical Back Button is pressed or a back navigation has been requested.
public event EventHandler<RoutedEventArgs> BackRequested
Event Type
Closed
Fired when the window is closed.
public event EventHandler? Closed
Event Type
Opened
Fired when the window is opened.
public event EventHandler? Opened
Event Type
ScalingChanged
Gets or sets a method called when the TopLevel's scaling changes.
public event EventHandler? ScalingChanged