* Added View.DefaultCommand etc... Started on dedicated scenario * Fixed un-shifted hotkeys -> Fixed Key Equals. Fixed WindowsDriver passing wrong key. Etc. * Fixed Key Bindings and HotKeys * Fixed Key Bindings and HotKeys * Label now correctly supports hotkey * Disabled unix hot keys because they are annoying and get in the way * Updated nuget. fixed warnings * Trying to fix ci/ci issue * Trying to fix ci/ci issue * Trying to fix ci/ci issue * Changed TextChangingEventArgs to inherit from CancelEventArgs * TextChangingEventArgs -> TextEventArgs * Simplified Text events by having only on args class * Fixed unit tests fail * Simplified by removing TitleEventArgs * POC of Title being primary for hotkey. Label and Button hacked to work * POC of Title being primary for hotkey. Label and Button hacked to work - all unit tests pass * Dropped Microsoft.NETFramework.ReferenceAssemblies * Fixed Dialogs scenario hotkeys * Fixed build warnings * Fixed Border Title render bug * Regiggering default command handling * Regiggering default command handling * Checkbox clean up * Added StateEventArgs POC * Command.Default -> Command.HotKey * Command.Default -> Command.HotKey - fixed TableView * Command.Default -> Command.HotKey - fixed TableView * Updated reactive example * Fixed Toplevel.BringOverlappedTopToFront - was reordering SubViews when it shouldn't * WIP - broke * Finished impl of StateEventArgs * Deleted ToggleEventArgs.cs. Added StateEventArgs.cs * XML doc fix * Removed old code * Removed commented out code * Label.Clicked -> Label.Accept (missed this before) * Removed Labels as Buttons scenario as it's not really useful * Moved SubView tests to own file * Moved SubView tests to own file * Simplified Text test * Added OnAccept test * Deleted DefaultCommand * Modernized CheckBox * New button test * Cleaned up RadioGroup; added tests * KeyCode->Key in ListView * Added ListView unit tests * ListView now does Accept correctly * TreeView now does Accept correctly * Cleaned up some TextField tests * TextView now handles Accept properly; updated CharMap and Adornments scenarios to test * Fixed ComboBox to deal with TextView now handles Accept properly; updated CharMap and Adornments scenarios to test * Removed un-needed using statement
This is a sample app that shows how to use System.Reactive and ReactiveUI with Terminal.Gui. The app uses the MVVM architecture that may seem familiar to folks coming from WPF, Xamarin Forms, UWP, Avalonia, or Windows Forms. In this app, we implement the data bindings using ReactiveUI WhenAnyValue syntax and Pharmacist — a tool that converts all events in a NuGet package into observable wrappers.
Scheduling
In order to use reactive extensions scheduling, copy-paste the TerminalScheduler.cs file into your project, and add the following lines to the composition root of your Terminal.Gui application:
Application.Init ();
RxApp.MainThreadScheduler = TerminalScheduler.Default;
RxApp.TaskpoolScheduler = TaskPoolScheduler.Default;
Application.Run (new RootView (new RootViewModel ()));
From now on, you can use .ObserveOn(RxApp.MainThreadScheduler) to return to the main loop from a background thread. This is useful when you have a IObservable<TValue> updated from a background thread, and you wish to update the UI with TValues received from that observable.
Data Bindings
If you wish to implement OneWay data binding, then use the WhenAnyValue ReactiveUI extension method that listens to INotifyPropertyChanged events of the specified property, and converts that events into IObservable<TProperty>:
// 'usernameInput' is 'TextField'
ViewModel
.WhenAnyValue (x => x.Username)
.BindTo (usernameInput, x => x.Text);
Note that your view model should implement INotifyPropertyChanged or inherit from a ReactiveObject. If you wish to implement OneWayToSource data binding, then install Pharmacist.MSBuild into your project and listen to e.g. TextChanged event of a TextField:
// 'usernameInput' is 'TextField'
usernameInput
.Events () // The Events() extension is generated by Pharmacist.
.TextChanged
.Select (old => usernameInput.Text)
.DistinctUntilChanged ()
.BindTo (ViewModel, x => x.Username);
If you combine OneWay and OneWayToSource data bindings, you get TwoWay data binding. Also be sure to use the string type instead of the string type. Invoking commands should be as simple as this:
// 'clearButton' is 'Button'
clearButton
.Events ()
.Clicked
.InvokeCommand (ViewModel, x => x.Clear);