feat: Add VM switch selection logic and persist custom names/IPs in UI

- Implemented Select-VMSwitchFromConfig function to handle VM switch selection based on configuration.
- Enhanced Register-EventHandlers to persist custom VM switch name and IP address when 'Other' is selected.
- Improved user experience by ensuring relevant fields are populated correctly based on user input and configuration settings.
This commit is contained in:
rbalsleyMSFT
2025-08-12 12:14:03 -07:00
parent 3c545be5c5
commit 78d7bb9262
2 changed files with 77 additions and 2 deletions
@@ -207,7 +207,12 @@ function Register-EventHandlers {
$selectedItem = $eventSource.SelectedItem
if ($selectedItem -eq 'Other') {
$localState.Controls.txtCustomVMSwitchName.Visibility = 'Visible'
$localState.Controls.txtVMHostIPAddress.Text = '' # Clear IP for custom
if ([string]::IsNullOrWhiteSpace($localState.Controls.txtCustomVMSwitchName.Text) -and $null -ne $localState.Data.customVMSwitchName) {
$localState.Controls.txtCustomVMSwitchName.Text = $localState.Data.customVMSwitchName
}
if ($null -ne $localState.Data.customVMHostIP -and -not [string]::IsNullOrWhiteSpace($localState.Data.customVMHostIP)) {
$localState.Controls.txtVMHostIPAddress.Text = $localState.Data.customVMHostIP
}
}
else {
$localState.Controls.txtCustomVMSwitchName.Visibility = 'Collapsed'
@@ -220,6 +225,24 @@ function Register-EventHandlers {
}
})
# Persist custom VM switch name/IP when user edits them while 'Other' is selected
$State.Controls.txtVMHostIPAddress.Add_LostFocus({
param($eventSource, $routedEventArgs)
$window = [System.Windows.Window]::GetWindow($eventSource)
$localState = $window.Tag
if ($localState.Controls.cmbVMSwitchName.SelectedItem -eq 'Other') {
$localState.Data.customVMHostIP = $localState.Controls.txtVMHostIPAddress.Text
}
})
$State.Controls.txtCustomVMSwitchName.Add_LostFocus({
param($eventSource, $routedEventArgs)
$window = [System.Windows.Window]::GetWindow($eventSource)
$localState = $window.Tag
if ($localState.Controls.cmbVMSwitchName.SelectedItem -eq 'Other') {
$localState.Data.customVMSwitchName = $localState.Controls.txtCustomVMSwitchName.Text
}
})
# Windows Settings tab Event Handlers
$State.Controls.txtISOPath.Add_TextChanged({
param($eventSource, $textChangedEventArgs)