Class Scenario
- Namespace
- UICatalog
- Assembly
- UICatalog.dll
Base class for each demo/scenario.
To define a new scenario:
-
Create a new
.cs
file in theScenarios directory that derives from Scenario. - Annotate the Scenario derived class with a ScenarioMetadata attribute specifying the scenario's name and description.
- Add one or more ScenarioCategory attributes to the class specifying which categories the scenario belongs to. If you don't specify a category the scenario will show up in "_All".
- Implement the Main() override which will be called when a user selects the scenario to run.
The UI Catalog program uses reflection to find all scenarios and adds them to the ListViews. Press ENTER to run the selected scenario. Press the default quit key to quit.
public class Scenario : IDisposable
- Inheritance
-
Scenario
- Implements
- Derived
- Inherited Members
- Extension Methods
Examples
The example below is provided in the Scenarios
directory as a generic sample that can be copied and re-named:
using Terminal.Gui;
namespace UICatalog.Scenarios;
[ScenarioMetadata ("Generic", "Generic sample - A template for creating new Scenarios")]
[ScenarioCategory ("Controls")]
public sealed class MyScenario : Scenario
{
public override void Main ()
{
// Init
Application.Init ();
// Setup - Create a top-level application window and configure it.
Window appWindow = new ()
{
Title = GetQuitKeyAndName (),
};
var button = new Button { X = Pos.Center (), Y = Pos.Center (), Text = "Press me!" };
button.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed the button!", "Ok");
appWindow.Add (button);
// Run - Start the application.
Application.Run (appWindow);
appWindow.Dispose ();
// Shutdown - Calling Application.Shutdown is required.
Application.Shutdown ();
}
}
Properties
Methods
- Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
- GetCategories()
Helper function to get the list of categories a Scenario belongs to (defined in ScenarioCategory)
- GetDescription()
Helper to get the Scenario Description (defined in ScenarioMetadata)
- GetName()
Helper to get the Scenario Name (defined in ScenarioMetadata)
- GetQuitKeyAndName()
Helper to get the QuitKey and the Scenario Name (defined in ScenarioMetadata)
- GetScenarios()
Returns a list of all Scenario instanaces defined in the project, sorted by Name. https://stackoverflow.com/questions/5411694/get-all-inherited-classes-of-an-abstract-class
- ToString()
Gets the Scenario Name + Description with the Description padded based on the longest known Scenario name.