I am working on a GUI project over here, my issue is related with disabling a submit button. The GUI is a Wizard and in some pages, there would be more than one Submit Buttons.
Whenever the user clicks on any of the Submit Button, some verifications will be done and if everything is good the next Input box will be enabled (as it is disabled by default in the XAML). when the user changes the text of the second Input Box, its Submit Button allocated for this Input Box will be enabled.
To make sure the user will not do something wrong, I want to disable the first Submit Button when the user changes the text of the second input box.
At this point, Whenever the user changes the text of an input box, the corresponding submits button gets enabled fine with no issues but the previous submit button do not get disabled.
Below is a PIC of one of the pages and as you can see the second submit button get enabled but the first did not get disabled.
My code is as follow:
# Main Page Input Boxes.
# Enable Submit Buttons.
$Global:GuiHash.WizardMainPageInputBox1.Add_TextChanged({$Global:GuiHash.WizardMainPageSubmitButton1.IsEnabled="True"})
$Global:GuiHash.WizardMainPageInputBox2.Add_TextChanged({$Global:GuiHash.WizardMainPageSubmitButton2.IsEnabled="True"})
$Global:GuiHash.WizardMainPageInputBox3.Add_TextChanged({$Global:GuiHash.WizardMainPageSubmitButton3.IsEnabled="True"})
# Clear default text from the box and disable priviouse submit buttons.
$Global:GuiHash.WizardMainPageInputBox1.Add_GotFocus({If ($Global:GuiHash.WizardMainPageInputBox1.Text -eq "NSX Manager FQDN:") {$Global:GuiHash.WizardMainPageInputBox1.Dispatcher.Invoke([action]{$Global:GuiHash.WizardMainPageInputBox1.Text = ""})}})
$Global:GuiHash.WizardMainPageInputBox2.Add_GotFocus({
Wait-Debugger
If ($Global:GuiHash.WizardMainPageInputBox2.Text -eq "NSX Manager Admin Password:") {$Global:GuiHash.WizardMainPageInputBox2.Dispatcher.Invoke([action]{$Global:GuiHash.WizardMainPageInputBox2.Text = ""})}
$Global:GuiHash.WizardMainPageSubmitButton1.IsEnabled="False"
})
$Global:GuiHash.WizardMainPageInputBox3.Add_GotFocus({If ($Global:GuiHash.WizardMainPageInputBox3.Text -eq "Output folder path:") {$Global:GuiHash.WizardMainPageInputBox3.Dispatcher.Invoke([action]{$Global:GuiHash.WizardMainPageInputBox3.Text = ""}); $Global:GuiHash.WizardMainPageSubmitButton2.IsEnabled= "False"}})
When I try to debug this using debug-runspace, I do not get any error on the line of code where it should disable the submit button.
Line of Code to disable the submit button:
$Global:GuiHash.WizardMainPageSubmitButton1.IsEnabled="False"
Debug Runspaces:
PS C:\Users\Administrator> Debug-Runspace Runspace11
Debugging Runspace: Runspace11
To end the debugging session type the 'Detach' command at the debugger prompt, or type 'Ctrl+C' otherwise.
Stopped at: If ($Global:GuiHash.WizardMainPageInputBox2.Text -eq "NSX Manager Admin Password:") {$Global:GuiHash.WizardMainPageInputBox2.Dispatcher.Invoke([action]{$Global:GuiHash.WizardMainPageInputBox2.Text = ""})}
[DBG]: [Process:7116]: [Runspace11]: PS C:\Users\Administrator>>
Stopped at: If ($Global:GuiHash.WizardMainPageInputBox2.Text -eq "NSX Manager Admin Password:") {$Global:GuiHash.WizardMainPageInputBox2.Dispatcher.Invoke([action]{$Global:GuiHash.WizardMainPageInputBox2.Text = ""})}
[DBG]: [Process:7116]: [Runspace11]: PS C:\Users\Administrator>>
Stopped at: $Global:GuiHash.WizardMainPageSubmitButton1.IsEnabled="False"
[DBG]: [Process:7116]: [Runspace11]: PS C:\Users\Administrator>>
Stopped at: })
[DBG]: [Process:7116]: [Runspace11]: PS C:\Users\Administrator>>