WizardAsView.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #nullable enable
  2. namespace UICatalog.Scenarios;
  3. [ScenarioMetadata ("WizardAsView", "Shows using the Wizard class in an non-modal way")]
  4. [ScenarioCategory ("Wizards")]
  5. public class WizardAsView : Scenario
  6. {
  7. public override void Main ()
  8. {
  9. Application.Init ();
  10. // MenuBar
  11. MenuBar menu = new ();
  12. menu.Add (
  13. new MenuBarItem (
  14. "_File",
  15. [
  16. new MenuItem
  17. {
  18. Title = "_Restart Configuration...",
  19. Action = () => MessageBox.Query (
  20. Application.Instance,
  21. "Wizard",
  22. "Are you sure you want to reset the Wizard and start over?",
  23. "Ok",
  24. "Cancel"
  25. )
  26. },
  27. new MenuItem
  28. {
  29. Title = "Re_boot Server...",
  30. Action = () => MessageBox.Query (
  31. Application.Instance,
  32. "Wizard",
  33. "Are you sure you want to reboot the server start over?",
  34. "Ok",
  35. "Cancel"
  36. )
  37. },
  38. new MenuItem
  39. {
  40. Title = "_Shutdown Server...",
  41. Action = () => MessageBox.Query (
  42. Application.Instance,
  43. "Wizard",
  44. "Are you sure you want to cancel setup and shutdown?",
  45. "Ok",
  46. "Cancel"
  47. )
  48. }
  49. ]
  50. )
  51. );
  52. // No need for a Title because the border is disabled
  53. Wizard wizard = new ()
  54. {
  55. X = 0,
  56. Y = Pos.Bottom (menu),
  57. Width = Dim.Fill (),
  58. Height = Dim.Fill (),
  59. ShadowStyle = ShadowStyle.None
  60. };
  61. // Set Modal to false to cause the Wizard class to render without a frame and
  62. // behave like an non-modal View (vs. a modal/pop-up Window).
  63. // wizard.Modal = false;
  64. wizard.MovingBack += (s, args) =>
  65. {
  66. //args.Cancel = true;
  67. //actionLabel.Text = "Moving Back";
  68. };
  69. wizard.MovingNext += (s, args) =>
  70. {
  71. //args.Cancel = true;
  72. //actionLabel.Text = "Moving Next";
  73. };
  74. wizard.Finished += (s, args) =>
  75. {
  76. //args.Cancel = true;
  77. MessageBox.Query ((s as View)?.App, "Setup Wizard", "Finished", "Ok");
  78. Application.RequestStop ();
  79. };
  80. wizard.Cancelled += (s, args) =>
  81. {
  82. int? btn = MessageBox.Query ((s as View)?.App, "Setup Wizard", "Are you sure you want to cancel?", "Yes", "No");
  83. args.Cancel = btn == 1;
  84. if (btn == 0)
  85. {
  86. Application.RequestStop ();
  87. }
  88. };
  89. // Add 1st step
  90. WizardStep firstStep = new () { Title = "End User License Agreement" };
  91. wizard.AddStep (firstStep);
  92. firstStep.NextButtonText = "Accept!";
  93. firstStep.HelpText =
  94. "This is the End User License Agreement.\n\n\n\n\n\nThis is a test of the emergency broadcast system. This is a test of the emergency broadcast system.\nThis is a test of the emergency broadcast system.\n\n\nThis is a test of the emergency broadcast system.\n\nThis is a test of the emergency broadcast system.\n\n\n\nThe end of the EULA.";
  95. // Add 2nd step
  96. WizardStep secondStep = new () { Title = "Second Step" };
  97. wizard.AddStep (secondStep);
  98. secondStep.HelpText =
  99. "This is the help text for the Second Step.\n\nPress the button to change the Title.\n\nIf First Name is empty the step will prevent moving to the next step.";
  100. Label buttonLbl = new () { Text = "Second Step Button: ", X = 0, Y = 0 };
  101. Button button = new ()
  102. {
  103. Text = "Press Me to Rename Step",
  104. X = Pos.Right (buttonLbl),
  105. Y = Pos.Top (buttonLbl)
  106. };
  107. button.Accepting += (s, e) =>
  108. {
  109. secondStep.Title = "2nd Step";
  110. MessageBox.Query ((s as View)?.App,
  111. "Wizard Scenario",
  112. "This Wizard Step's title was changed to '2nd Step'",
  113. "Ok"
  114. );
  115. };
  116. secondStep.Add (buttonLbl, button);
  117. Label lbl = new () { Text = "First Name: ", X = Pos.Left (buttonLbl), Y = Pos.Bottom (buttonLbl) };
  118. TextField firstNameField = new () { Text = "Number", Width = 30, X = Pos.Right (lbl), Y = Pos.Top (lbl) };
  119. secondStep.Add (lbl, firstNameField);
  120. lbl = new () { Text = "Last Name: ", X = Pos.Left (buttonLbl), Y = Pos.Bottom (lbl) };
  121. TextField lastNameField = new () { Text = "Six", Width = 30, X = Pos.Right (lbl), Y = Pos.Top (lbl) };
  122. secondStep.Add (lbl, lastNameField);
  123. // Add last step
  124. WizardStep lastStep = new () { Title = "The last step" };
  125. wizard.AddStep (lastStep);
  126. lastStep.HelpText =
  127. "The wizard is complete!\n\nPress the Finish button to continue.\n\nPressing Esc will cancel.";
  128. Window window = new ();
  129. window.Add (menu, wizard);
  130. Application.Run (window);
  131. window.Dispose ();
  132. Application.Shutdown ();
  133. }
  134. }