ActionCard
Wisej.NET 4.2.0+
An ActionCard is a single task, record or notification presented as a card: an icon, a title with an optional badge beside it, a description, a metadata line, and a row of command buttons on the right. Clicking the card header raises Click (and toggles Selected when the card is selectable); clicking a command raises ActionClick and never reaches the header. Below the header the card can host any Wisej control as its Content — a text box for a note, a progress bar, a small grid.
Reach for it where a screen would otherwise be a hand-built Panel of labels and buttons repeated for every item: an inbox of approvals, a list of pending jobs, a dashboard of things that need attention. All text is literal, never HTML, so data from the database can go straight into it.
ActionCardList is its data-bound companion. It binds to a list, a BindingSource or a DataTable and shows one card per record, but only a fixed window of cards ever exists — scrolling disposes the cards that leave the view and creates the ones that enter it — so a list of ten thousand records costs the same as a list of thirty. Where the DataRepeater repeats a template you design, the list repeats a finished card; where the ListView shows records as tiles, each card here carries its own commands.
For a complete list of properties, methods, and events, see the API documentation of ActionCard and ActionCardList.
Features
Card Content
The card's text is four properties: Title, Description, Meta (a muted line for dates, owners or counts) and Badge. Icon takes an image URL or a theme image name. The icon and the badge are tinted by IconTone and BadgeTone, both of type ActionCardTone: Neutral, Primary, Success, Warning or Danger, mapped to the theme's semantic colours.
var card = new ActionCard
{
Title = "Rotate TLS certificates",
Description = "12 gateways in Europe and Africa",
Meta = "Assigned to Platform team · opened 2 days ago",
Icon = "Images/certificate.svg",
IconTone = ActionCardTone.Primary,
Badge = "Due in 3 days",
BadgeTone = ActionCardTone.Warning
};
Commands
Actions is an ordered CardActionCollection of CardAction objects, each with a Text, an optional Icon, a Name your code uses to tell them apart, and Primary and Enabled flags. A primary command is drawn as the filled button. Changing a command, or the collection, updates the card immediately.
When a command is clicked, ActionClick is raised with a CardActionEventArgs carrying the Action and its Index. A disabled command raises nothing.
Selection
Click is raised whenever the header is activated by pointer or keyboard. Set Selectable to true to have each activation also toggle Selected, which outlines the card in the primary colour and raises SelectedChanged. Code can set Selected whether or not the card is selectable.
Elevation picks the surface: Flat (a bordered card, the default) or Raised (bordered with a subtle shadow).
Hosted Content
Content places one Wisej control below the header, filling the card's width and keeping its own Height. The card adds the control to its Controls and disposes it with the card; assigning another control, or null, detaches the old one without disposing it. Size the card to fit: the card does not grow to its content.
card.Content = new TextBox { Watermark = "Deployment notes", Height = 32 };
card.Height = 156;
ActionCardList
ActionCardList binds DataSource (and optionally DataMember) and maps each record onto a card through DisplayMembers. A mapping left empty uses the property of the conventional name when the record has one — Title, Description, Meta, Icon, Badge, IconTone, BadgeTone — so a record shaped like the card needs no mapping at all. Tone properties can hold an ActionCardTone or its name as a string.
Every card has the same height, ItemHeight (108 by default), separated by ItemSpacing pixels. WindowSize is the number of cards that exist at once (32 by default, at most 200); it must cover the visible cards plus a few off screen. Commands and content are not part of the record, so they are added in CardCreated, which runs each time a card is created for a record. ItemClick is raised when a card's header is clicked.
A BindingList<T>, a DataTable or a BindingSource notifies the list of changes on its own. A plain List<T> does not: call RefreshData() after changing it.
How To
Handle a Command
Give each command a Name and switch on it in ActionClick.
this.actionCard1.Actions.Add(new CardAction { Name = "snooze", Text = "Snooze" });
this.actionCard1.Actions.Add(new CardAction { Name = "run", Text = "Run now", Primary = true });
this.actionCard1.ActionClick += (sender, e) =>
{
switch (e.Action.Name)
{
case "run":
e.Action.Enabled = false;
this.actionCard1.Badge = "Running";
this.actionCard1.BadgeTone = ActionCardTone.Primary;
StartCertificateRotation();
break;
case "snooze":
this.actionCard1.Meta = "Snoozed until tomorrow";
break;
}
};
Bind a List of Records
A record whose properties carry the conventional names binds without mapping; the others are mapped through DisplayMembers. Set the mappings before DataSource.
public class Job
{
public string Name { get; set; }
public string Region { get; set; }
public string Due { get; set; }
public ActionCardTone BadgeTone { get; set; }
}
this.actionCardList1.DisplayMembers.Title = "Name";
this.actionCardList1.DisplayMembers.Description = "Region";
this.actionCardList1.DisplayMembers.Badge = "Due";
this.actionCardList1.DataSource = new BindingList<Job>(jobService.GetOpenJobs());
Add Commands to Every Card in a List
Cards in an ActionCardList are transient: a card that scrolls out of the window is disposed, and a new one is created when it comes back. Attach commands and handlers in CardCreated, and keep anything that has to survive scrolling in the record, which DataItem hands back.
this.actionCardList1.CardCreated += (sender, e) =>
{
var job = (Job)e.DataItem;
e.Card.Selectable = true;
e.Card.Actions.Add(new CardAction { Name = "open", Text = "Open" });
e.Card.Actions.Add(new CardAction { Name = "close", Text = "Close", Primary = true });
e.Card.ActionClick += (s, a) =>
{
if (a.Action.Name == "close")
jobService.Close(job);
else
ShowJob(job);
};
};
this.actionCardList1.ItemClick += (sender, e) => ShowJob((Job)e.DataItem);
Advanced
JavaScript Widget
| Item | Description |
|---|---|
| Class name | "wisej.web.ActionCard", "wisej.web.ActionCardList" |
| Theme appearance | "actioncard", "actioncardlist", see Themes. |
| Child components | ActionCard: "row" holds the header and the commands. "header" is the clickable area holding "icon" and "text". "text" holds "heading" (with "title" and "badge"), "description" and "meta". "actions" holds the command buttons. "content" hosts the Content control. See JavaScript. |