Search Results for

Show / Hide Table of Contents

# Class Scenario

Base class for each demo/scenario.

To define a new scenario:

1. Create a new `.cs` file in the Scenarios directory that derives from Scenario.
2. Annotate the Scenario derived class with a Scenario.ScenarioMetadata attribute specifying the scenario's name and description.
3. Add one or more Scenario.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".
4. Implement the Setup() override which will be called when a user selects the scenario to run.
5. Optionally, implement the Init(Toplevel, ColorScheme) and/or Run() overrides to provide a custom implementation.

The UI Catalog program uses reflection to find all scenarios and adds them to the ListViews. Press ENTER to run the selected scenario. Press CTRL-Q to exit it. /

##### Inheritance

System.Object
Scenario
AllViewsTester
AutoSizeAndDirectionText
BackgroundWorkerCollection
BasicColors
Borders
BordersComparisons
BordersOnFrameView
BordersOnToplevel
BordersOnWindow
Buttons
CharacterMap
ClassExplorer
Clipping
ComboBoxIteration
ComputedLayout
ContextMenus
CsvEditor
Dialogs
DynamicMenuBar
DynamicStatusBar
Editor
GraphViewExample
HexEditor
InteractiveTree
InvertColors
Keys
LabelsAsLabels
LineViewExample
ListsAndCombos
ListViewWithSelection
MessageBoxes
Mouse
MultiColouredTable
MyScenario
Notepad
Progress
ProgressBarStyles
Scrolling
SendKeys
SingleBackgroundWorker
SyntaxHighlighting
TableEditor
TabViewExample
Text
TextAlignments
TextAlignmentsAndDirections
TextFormatterDemo
TextViewAutocompletePopup
Threading
TimeAndDate
TreeUseCases
TreeViewFileSystem
UnicodeInMenu
WindowsAndFrameViews

##### Implements

System.IDisposable

##### Inherited Members

System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)

###### Namespace: UICatalog

###### Assembly: UICatalog.dll

##### Syntax

    public class Scenario : IDisposable

##### 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 {
        [ScenarioMetadata (Name: "Generic", Description: "Generic sample - A template for creating new Scenarios")]
        [ScenarioCategory ("Controls")]
        class MyScenario : Scenario {
            public override void Setup ()
            {
                // Put your scenario code here, e.g.
                Win.Add (new Button ("Press me!") {
                    X = Pos.Center (),
                    Y = Pos.Center (),
                    Clicked = () => MessageBox.Query (20, 7, "Hi", "Neat?", "Yes", "No")
                });
            }
        }
    }

### Properties

#### Top

The Top level for the Scenario. This should be set to Top in most cases.

##### Declaration

    public Toplevel Top { get; set; }

##### Property Value

Type | Description
--- | ---
Toplevel |

#### Win

The Window for the Scenario. This should be set within the Top in most cases.

##### Declaration

    public Window Win { get; set; }

##### Property Value

Type | Description
--- | ---
Window |

### Methods

#### Dispose()

##### Declaration

    public void Dispose()

#### Dispose(Boolean)

##### Declaration

    protected virtual void Dispose(bool disposing)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Boolean | disposing |

#### GetCategories()

Helper function to get the list of categories a Scenario belongs to (defined in Scenario.ScenarioCategory)

##### Declaration

    public List<string> GetCategories()

##### Returns

Type | Description
--- | ---
System.Collections.Generic.List<System.String> | list of category names

#### GetDerivedClasses<T>()

Returns an instance of each Scenario defined in the project. https://stackoverflow.com/questions/5411694/get-all-inherited-classes-of-an-abstract-class

##### Declaration

    public static List<Type> GetDerivedClasses<T>()

##### Returns

Type | Description
--- | ---
System.Collections.Generic.List<System.Type> |

##### Type Parameters

Name | Description
--- | ---
T |

#### GetDescription()

Helper to get the Scenario Description (defined in Scenario.ScenarioMetadata)

##### Declaration

    public string GetDescription()

##### Returns

Type | Description
--- | ---
System.String |

#### GetName()

Helper to get the Scenario Name (defined in Scenario.ScenarioMetadata)

##### Declaration

    public string GetName()

##### Returns

Type | Description
--- | ---
System.String |

#### Init(Toplevel, ColorScheme)

Helper that provides the default Window implementation with a frame and label showing the name of the Scenario and logic to exit back to the Scenario picker UI. Override Init(Toplevel, ColorScheme) to provide any Toplevel behavior needed.

##### Declaration

    public virtual void Init(Toplevel top, ColorScheme colorScheme)

##### Parameters

Type | Name | Description
--- | --- | ---
Toplevel | top | The Toplevel created by the UI Catalog host.
ColorScheme | colorScheme | The colorscheme to use.

##### Remarks

The base implementation calls Init(ConsoleDriver, IMainLoopDriver), sets Top to the passed in Toplevel, creates a Window for Win and adds it to Top.

Overrides that do not call the base.Run(), must call Init(ConsoleDriver, IMainLoopDriver) before creating any views or calling other Terminal.Gui APIs.

#### RequestStop()

Stops the scenario. Override to change shutdown behavior for the Scenario.

##### Declaration

    public virtual void RequestStop()

#### Run()

Runs the Scenario. Override to start the Scenario using a Toplevel different than `Top`.

##### Declaration

    public virtual void Run()

##### Remarks

Overrides that do not call the base.Run(), must call Shutdown() before returning.

#### Setup()

Override this to implement the Scenario setup logic (create controls, etc...).

##### Declaration

    public virtual void Setup()

##### Remarks

This is typically the best place to put scenario logic code.

#### ToString()

##### Declaration

    public override string ToString()

##### Returns

Type | Description
--- | ---
System.String |

##### Overrides

System.Object.ToString()

### Implements

System.IDisposable