Skip to content

Fix workaround in Segmented control#699

Merged
Arlodotexe merged 2 commits into
CommunityToolkit:mainfrom
AndrewKeepCoding:fix-segemented-control-workaround
Jul 14, 2025
Merged

Fix workaround in Segmented control#699
Arlodotexe merged 2 commits into
CommunityToolkit:mainfrom
AndrewKeepCoding:fix-segemented-control-workaround

Conversation

@AndrewKeepCoding
Copy link
Copy Markdown
Member

This commit modifies the OnApplyTemplate method in the Segmented class to set SelectedIndex to -1 and then assign _internalSelectedIndex if _hasLoaded is false. This ensures the selected index is reset before applying the internal selection and marks the template as loaded.

Fixes

#698

PR Type

What kind of change does this PR introduce?

  • Bugfix

What is the current behavior?

The selected item is not rendered as selected when in XAML:

  • 2 SegmentedItems are declared
    and
  • SelectedIndex is set to 1.
<toolkit:Segmented SelectedIndex="1">
    <toolkit:SegmentedItem Content="Item 1" />
    <toolkit:SegmentedItem Content="Item 2" />
</toolkit:Segmented>

image

What is the new behavior?

The selected item is rendered as expected.
image

PR Checklist

Please check if your PR fulfills the following requirements:

  • Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • Based off latest main branch of toolkit
  • Contains NO breaking changes

Other information

… template application

This commit modifies the `OnApplyTemplate` method in the `Segmented` class to set `SelectedIndex` to `-1` and then assign `_internalSelectedIndex` if `_hasLoaded` is false. This ensures the selected index is reset before applying the internal selection and marks the template as loaded.
@Arlodotexe Arlodotexe self-requested a review July 14, 2025 18:35
Copy link
Copy Markdown
Member

@Arlodotexe Arlodotexe left a comment

Choose a reason for hiding this comment

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

I was able to reproduce the issue locally and have confirmed that this change fixes it. Thanks, approved!

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