Skip to content

Commit 5fe4f06

Browse files
committed
Added HasLoaded
1 parent 6198f9e commit 5fe4f06

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

components/SegmentedControl/src/Segmented/Segmented.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace CommunityToolkit.Labs.WinUI;
99
public partial class Segmented : ListViewBase
1010
{
1111
private int _internalSelectedIndex = -1;
12+
private bool _hasLoaded = false;
13+
1214
public Segmented()
1315
{
1416
this.DefaultStyleKey = typeof(Segmented);
@@ -26,7 +28,11 @@ protected override bool IsItemItsOwnContainerOverride(object item)
2628
protected override void OnApplyTemplate()
2729
{
2830
base.OnApplyTemplate();
29-
SelectedIndex = _internalSelectedIndex;
31+
if (!_hasLoaded)
32+
{
33+
SelectedIndex = _internalSelectedIndex;
34+
_hasLoaded = true;
35+
}
3036
PreviewKeyDown -= Segmented_PreviewKeyDown;
3137
PreviewKeyDown += Segmented_PreviewKeyDown;
3238
}

0 commit comments

Comments
 (0)