Page View Model
Overview
PageViewModel<TContext> is the primary abstract class for top‑level pages in Asv.Avalonia. It inherits from ViewModel<TContext> and implements the IPage interface.
Core Components
Registration
Pages must be registered in the DI container via the builder. Use the Pages.Register method to register a page with its view:
Visuals
Each page contains a Header, Icon (with color), and Status (also with color). These can be customized as needed. This information is typically displayed in the shell tabs.
Close Workflow
When a page is closed via a tab, the TryCloseAsync method is called with the force argument set to false. It works as follows:
Asks child view‑models for pending‑close reasons via
RequestChildCloseApproval. This method raises thePageCloseAttemptEventrouting event, which view models can catch to add restrictions.If reasons to prevent closing exist, it shows the
UnsavedChangesDialogPrefab. If the user cancels the dialog, the method returns early.Calls
RequestClose, which raises the bubblingPageCloseRequestedEventto notify the shell that the page is ready to be closed. The shell handles the event and performs the actual close.
Undo History
Each page exposes an UndoHistory property of type IUndoHistory<IViewModel>, backed by the IUndoHistoryStore supplied through IPageContext. It records the operations performed on the page for undo and redo actions.
Example
A simple usage example looks like this:
This page has no child view models (subpages or widgets), so it does not override GetChildren() — the base implementation already returns an empty collection.
API
IPage
Represents a page in the application shell. Defines a common contract for navigable pages, including visual representation (icon, status, header), undo history, layout management, and controlled closing behavior.
Property | Type | Description |
|---|---|---|
|
| Gets or sets the main icon representing the page in the tab menu. |
|
| Gets or sets the color of the page icon. |
|
| Gets an optional status icon displayed alongside the page icon. |
|
| Gets the color of the status icon. |
|
| Gets or sets the header (title) of the page displayed in the tab menu. |
|
| Gets the undo history associated with the page. |
|
| Gets the layout manager associated with the page. |
|
| Command that initiates an attempt to close the page. |
Status and StatusColor are get-only on the contract; PageViewModel<TContext> exposes them as settable.
Method | Return Type | Description |
|---|---|---|
|
| Attempts to close the page. When |
IPageContext
Bundles the per-page construction data: the navigation arguments plus the undo and layout stores. PageContext is the standard implementation; NullPageContext.Instance is used at design time and returns NavArgs.Empty together with the null undo and layout stores.
Property | Type | Description |
|---|---|---|
|
| Gets the navigation arguments, forwarded to the base |
|
| Gets the store backing the page's |
|
| Gets the store backing the page's |
PageViewModel<TContext> : IPage
Represents a base view model for application pages.
Extends ViewModel<TContext> and provides standard page behavior such as close handling with restriction approval, undo history, layout management, and integration with the shell via routed events. Constrained to where TContext : class, IPage.
Constructor | Description |
|---|---|
| Protected. The |