Page View Model
Overview
PageViewModel<TContext> is the primary abstract class for top‑level pages in Asv.Avalonia. It inherits from ExtendableViewModel and implements the IPage interface.
Core Components
ExportPage attribute
You must apply the ExportPage(pageId) attribute to your page classes. This helps the MEF container find and register the view models.
Visuals
Each page contains a Title, 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
RequestCloseto notify the navigation service that the page is ready to be closed.
Command History
Each page contains its ICommandHistory property. It is used to store all commands executed on the page for undo and redo actions. See the Command Service article for more details.
Example
A simple usage example looks like this:
API
IPage
Represents a page in the application shell. Defines a common contract for navigable pages, including visual representation, command history, 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 or sets an optional status icon displayed alongside the page icon. |
|
| Gets or sets the color of the status icon. |
|
| Gets or sets the title of the page displayed in the tab menu. |
|
| Gets the command history associated with the page. |
|
| Command that initiates an attempt to close the page. |
Method | Return Type | Description |
|---|---|---|
|
| Attempts to close the page. When |
PageViewModel<TContext> : IPage
Represents a base view model for application pages.
Extends ExtendableViewModel<TContext> and provides standard page behavior such as close handling, change tracking, and integration with the shell navigation system.
Property | Type | Description |
|---|---|---|
|
| Indicates whether the page has unsaved changes. Used to control close confirmation logic. |
|
| Gets export metadata describing the origin module of the page. |
Method | Return Type | Description |
|---|---|---|
|
| Releases managed resources used by the page. |