WizardAsView.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. "Wizard",
  21. "Are you sure you want to reset the Wizard and start over?",
  22. "Ok",
  23. "Cancel"
  24. )
  25. },
  26. new MenuItem
  27. {
  28. Title = "Re_boot Server...",
  29. Action = () => MessageBox.Query (
  30. "Wizard",
  31. "Are you sure you want to reboot the server start over?",
  32. "Ok",
  33. "Cancel"
  34. )
  35. },
  36. new MenuItem
  37. {
  38. Title = "_Shutdown Server...",
  39. Action = () => MessageBox.Query (
  40. "Wizard",
  41. "Are you sure you want to cancel setup and shutdown?",
  42. "Ok",
  43. "Cancel"
  44. )
  45. }
  46. ]
  47. )
  48. );
  49. // No need for a Title because the border is disabled
  50. Wizard wizard = new ()
  51. {
  52. X = 0,
  53. Y = Pos.Bottom (menu),
  54. Width = Dim.Fill (),
  55. Height = Dim.Fill (),
  56. ShadowStyle = ShadowStyle.None
  57. };
  58. // Set Modal to false to cause the Wizard class to render without a frame and
  59. // behave like an non-modal View (vs. a modal/pop-up Window).
  60. wizard.Modal = false;
  61. wizard.MovingBack += (s, args) =>
  62. {
  63. //args.Cancel = true;
  64. //actionLabel.Text = "Moving Back";
  65. };
  66. wizard.MovingNext += (s, args) =>
  67. {
  68. //args.Cancel = true;
  69. //actionLabel.Text = "Moving Next";
  70. };
  71. wizard.Finished += (s, args) =>
  72. {
  73. //args.Cancel = true;
  74. MessageBox.Query ("Setup Wizard", "Finished", "Ok");
  75. Application.RequestStop ();
  76. };
  77. wizard.Cancelled += (s, args) =>
  78. {
  79. int btn = MessageBox.Query ("Setup Wizard", "Are you sure you want to cancel?", "Yes", "No");
  80. args.Cancel = btn == 1;
  81. if (btn == 0)
  82. {
  83. Application.RequestStop ();
  84. }
  85. };
  86. // Add 1st step
  87. WizardStep firstStep = new () { Title = "End User License Agreement" };
  88. wizard.AddStep (firstStep);
  89. firstStep.NextButtonText = "Accept!";
  90. firstStep.HelpText =
  91. "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.";
  92. // Add 2nd step
  93. WizardStep secondStep = new () { Title = "Second Step" };
  94. wizard.AddStep (secondStep);
  95. secondStep.HelpText =
  96. "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.";
  97. Label buttonLbl = new () { Text = "Second Step Button: ", X = 0, Y = 0 };
  98. Button button = new ()
  99. {
  100. Text = "Press Me to Rename Step",
  101. X = Pos.Right (buttonLbl),
  102. Y = Pos.Top (buttonLbl)
  103. };
  104. button.Accepting += (s, e) =>
  105. {
  106. secondStep.Title = "2nd Step";
  107. MessageBox.Query (
  108. "Wizard Scenario",
  109. "This Wizard Step's title was changed to '2nd Step'",
  110. "Ok"
  111. );
  112. };
  113. secondStep.Add (buttonLbl, button);
  114. Label lbl = new () { Text = "First Name: ", X = Pos.Left (buttonLbl), Y = Pos.Bottom (buttonLbl) };
  115. TextField firstNameField = new () { Text = "Number", Width = 30, X = Pos.Right (lbl), Y = Pos.Top (lbl) };
  116. secondStep.Add (lbl, firstNameField);
  117. lbl = new () { Text = "Last Name: ", X = Pos.Left (buttonLbl), Y = Pos.Bottom (lbl) };
  118. TextField lastNameField = new () { Text = "Six", Width = 30, X = Pos.Right (lbl), Y = Pos.Top (lbl) };
  119. secondStep.Add (lbl, lastNameField);
  120. // Add last step
  121. WizardStep lastStep = new () { Title = "The last step" };
  122. wizard.AddStep (lastStep);
  123. lastStep.HelpText =
  124. "The wizard is complete!\n\nPress the Finish button to continue.\n\nPressing Esc will cancel.";
  125. Window topLevel = new ();
  126. topLevel.Add (menu, wizard);
  127. Application.Run (topLevel);
  128. topLevel.Dispose ();
  129. Application.Shutdown ();
  130. }
  131. }