Skip to content

Fix ListBoxItem visual state stuck when parent ListBox gains/loses focus#165

Merged
tedd merged 2 commits into
forge-listbox-parity-5850515012165907113from
copilot/sub-pr-148-yet-again
Mar 11, 2026
Merged

Fix ListBoxItem visual state stuck when parent ListBox gains/loses focus#165
tedd merged 2 commits into
forge-listbox-parity-5850515012165907113from
copilot/sub-pr-148-yet-again

Conversation

Copilot AI commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

ListBoxItem.UpdateVisualState() reads parentListBox.IsFocused to pick focused vs. unfocused selection colors, but was only invoked on IsSelected/IsFocused changes on the item itself. When the ListBox gained or lost focus (e.g., Tab navigation) without any item property changing, colors would get stuck in the wrong state.

Changes

  • ListBox — Override OnGotFocus()/OnLostFocus() to call a new NotifyContainersVisualStateChanged() helper that iterates ItemsPanelRoot.Children and refreshes each ListBoxItem's visual state immediately when the list box focus changes.
  • ListBoxItem — Widen UpdateVisualState() from private to internal so ListBox can invoke it.
// ListBox.cs
public override void OnGotFocus()
{
    base.OnGotFocus();
    NotifyContainersVisualStateChanged();  // items now see IsFocused=true
}

public override void OnLostFocus()
{
    base.OnLostFocus();
    NotifyContainersVisualStateChanged();  // items now see IsFocused=false
}

private void NotifyContainersVisualStateChanged()
{
    if (ItemsPanelRoot != null)
    {
        for (int i = 0; i < ItemsPanelRoot.Children.Count; i++)
        {
            if (ItemsPanelRoot.Children[i] is ListBoxItem lbi)
                lbi.UpdateVisualState();
        }
    }
}

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@tedd
tedd marked this pull request as ready for review March 11, 2026 13:17
Copilot AI review requested due to automatic review settings March 11, 2026 13:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.


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

…focus

Co-authored-by: tedd <493224+tedd@users.noreply.github.com>
@tedd
tedd merged commit b408a0c into forge-listbox-parity-5850515012165907113 Mar 11, 2026
1 check passed
Copilot AI changed the title [WIP] WIP Address feedback on ListBox Parity Integration PR Fix ListBoxItem visual state stuck when parent ListBox gains/loses focus Mar 11, 2026
Copilot stopped work on behalf of tedd due to an error March 11, 2026 13:18
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.

3 participants