Skip to content

fix: ComboBox default selection - use collection item reference#38

Merged
JusterZhu merged 1 commit into
mainfrom
fix/combo-default-selection
May 20, 2026
Merged

fix: ComboBox default selection - use collection item reference#38
JusterZhu merged 1 commit into
mainfrom
fix/combo-default-selection

Conversation

@JusterZhu
Copy link
Copy Markdown
Collaborator

Fix: ComboBox default selection error.

Root cause: Config.Platform was initialized as new PlatformItem(1,Windows) in the model, but Avalonia's ComboBox uses reference equality to find the selected item in ItemsSource. Even though PlatformItem is a record with value equality, the ComboBox couldn't match them.

Fix:

  • Set Config.Platform = Platforms[0] and Config.AppType = AppTypes[0] in ViewModel constructor - these ARE the collection items
  • Removed SelectedIndex=0 from XAML which conflicted with SelectedItem binding

Build: 0 errors

- Initialize Config.Platform/AppType from Platforms[0]/AppTypes[0] in VM
- Remove SelectedIndex=0 from XAML (conflicts with SelectedItem binding)
- Ensures selected item IS a collection item, not a separate instance
Copilot AI review requested due to automatic review settings May 20, 2026 15:34
@JusterZhu JusterZhu merged commit 1517a8a into main May 20, 2026
1 check failed
@JusterZhu JusterZhu deleted the fix/combo-default-selection branch May 20, 2026 15:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes incorrect default selection behavior in the Simulate view’s ComboBox controls by ensuring SelectedItem is set to the same object instances contained in the ItemsSource collections (avoiding reference-mismatch selection failures in Avalonia).

Changes:

  • Removed SelectedIndex="0" from the Platform/AppType ComboBox controls to avoid conflicting with SelectedItem bindings.
  • Initialized Config.Platform and Config.AppType in SimulateViewModel to Platforms[0] / AppTypes[0] (the actual collection item references).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Views/SimulateView.axaml Removes SelectedIndex so SelectedItem binding is the single source of truth for selection.
src/ViewModels/SimulateViewModel.cs Sets default Config selections to the ItemsSource instances to ensure Avalonia can resolve the selected item.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants