Skip to content

Notification

Namespace: Hex1b

Assembly: Hex1b.dll

Represents a notification that can be displayed to the user. Notifications are mutable state objects - modify properties directly and the UI will update.

csharp
public sealed class Notification

Inheritance

ObjectNotification

Constructors

Notification(string, string?)

Creates a new notification with the specified title.

Parameters:

  • title (String): The notification title.
  • body (String): Optional body text with additional details.
csharp
public Notification(string title, string? body = null)

Properties

Body

Optional body text with additional details.

Returns: String

csharp
public string? Body { get; set; }

CreatedAt

When this notification was created.

Returns: DateTimeOffset

csharp
public DateTimeOffset CreatedAt { get; }

PrimaryActionValue

The primary action button. Displayed as the main button on the notification.

Returns: NotificationAction

csharp
public NotificationAction? PrimaryActionValue { get; }

SecondaryActions

Secondary actions. Displayed in a dropdown menu next to the primary action.

Returns: IReadOnlyList<NotificationAction>

csharp
public IReadOnlyList<NotificationAction> SecondaryActions { get; }

TimeoutDuration

Optional timeout after which the notification hides from floating view. The notification remains in the notification panel until explicitly dismissed. If null, the notification floats indefinitely until dismissed.

Returns: Nullable<TimeSpan>

csharp
public TimeSpan? TimeoutDuration { get; set; }

Title

The notification title. Displayed prominently.

Returns: String

csharp
public string Title { get; set; }

Methods

OnDismiss(Func<NotificationEventContext, Task>)

Sets the handler invoked when this notification is dismissed.

Parameters:

Returns: Notification

This notification for fluent chaining.

csharp
public Notification OnDismiss(Func<NotificationEventContext, Task> handler)

OnTimeout(Func<NotificationEventContext, Task>)

Sets the handler invoked when this notification times out. Timeout hides the notification from floating view but keeps it in the panel.

Parameters:

Returns: Notification

This notification for fluent chaining.

csharp
public Notification OnTimeout(Func<NotificationEventContext, Task> handler)

PrimaryAction(string, Func<NotificationActionContext, Task>)

Sets the primary action for this notification.

Parameters:

Returns: Notification

This notification for fluent chaining.

csharp
public Notification PrimaryAction(string label, Func<NotificationActionContext, Task> handler)

SecondaryAction(string, Func<NotificationActionContext, Task>)

Adds a secondary action to this notification. Secondary actions appear in a dropdown menu next to the primary action.

Parameters:

Returns: Notification

This notification for fluent chaining.

csharp
public Notification SecondaryAction(string label, Func<NotificationActionContext, Task> handler)

Timeout(TimeSpan)

Sets the timeout duration for this notification. After the timeout, the notification hides from floating view but remains in the notification panel.

Parameters:

  • duration (TimeSpan): The duration after which the notification hides from floating view.

Returns: Notification

This notification for fluent chaining.

csharp
public Notification Timeout(TimeSpan duration)

Remarks

Notifications have a lifecycle: they are posted to a , appear as floating overlays, optionally time out (hiding from floating view but remaining in the notification panel), and can be dismissed entirely.

Use the fluent API to configure actions and lifecycle handlers:

csharp
var notification = new Notification("File saved", "document.txt saved successfully")
    .Timeout(TimeSpan.FromSeconds(5))
    .PrimaryAction("View", async ctx => await OpenFileAsync())
    .SecondaryAction("Undo", async ctx => await UndoSaveAsync())
    .OnDismiss(async ctx => await CleanupAsync());

e.Notifications.Post(notification);

Released under the MIT License.