ViewExtensions.cs 754 B

12345678910111213141516171819202122232425
  1. using System;
  2. using Terminal.Gui.ViewBase;
  3. using Terminal.Gui.Views;
  4. namespace ReactiveExample;
  5. public static class ViewExtensions
  6. {
  7. public static (Window MainView, TOut LastControl) AddControl<TOut> (this Window view, Action<TOut> action)
  8. where TOut : View, new()
  9. {
  10. TOut result = new ();
  11. action (result);
  12. view.Add (result);
  13. return (view, result);
  14. }
  15. public static (Window MainView, TOut LastControl) AddControlAfter<TOut> (this (Window MainView, View LastControl) view, Action<View, TOut> action)
  16. where TOut : View, new()
  17. {
  18. TOut result = new ();
  19. action (view.LastControl, result);
  20. view.MainView.Add (result);
  21. return (view.MainView, result);
  22. }
  23. }