Preserve node editor traffic type selection#8
Conversation
There was a problem hiding this comment.
Code Review
This pull request modifies the RefreshTrafficTypeNameOptions method in MainWindowViewModel.cs to preserve the selected traffic type when the options collection is rebuilt. Feedback suggests handling potential case-sensitivity mismatches between the stored traffic type and the synchronized collection to ensure WPF correctly restores the selection.
| // Re-announce the current selection after rebuilding the options collection so WPF restores the combo value. | ||
| if (!string.IsNullOrWhiteSpace(selectedTrafficType)) | ||
| { | ||
| OnPropertyChanged(nameof(SelectedNodeTrafficType)); | ||
| } |
There was a problem hiding this comment.
The selection restoration might fail if the casing of the traffic type in the TrafficTypeNameOptions collection differs from the selectedTrafficType captured from the profile. Since the collection is built using a case-insensitive Distinct(Comparer), it may contain a version of the string with different casing (e.g., "ABC" instead of "abc"). WPF's SelectedItem matching is case-sensitive, so it won't automatically restore the selection if the casing doesn't match exactly. Consider ensuring the profile's TrafficType is updated to match the casing found in the synchronized collection.
// Re-announce the current selection after rebuilding the options collection so WPF restores the combo value.
if (!string.IsNullOrWhiteSpace(selectedTrafficType))
{
var matchedType = TrafficTypeNameOptions.FirstOrDefault(name => Comparer.Equals(name, selectedTrafficType));
if (matchedType != null && SelectedNodeTrafficProfile != null)
{
SelectedNodeTrafficProfile.TrafficType = matchedType;
}
OnPropertyChanged(nameof(SelectedNodeTrafficType));
}
No description provided.