Skip to content
12 changes: 12 additions & 0 deletions components/Segmented/src/SegmentedItem/SegmentedItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.


namespace CommunityToolkit.WinUI.Controls;

/// <summary>
Expand All @@ -20,6 +21,17 @@ public partial class SegmentedItem : ListViewItem
public SegmentedItem()
{
this.DefaultStyleKey = typeof(SegmentedItem);
RegisterPropertyChangedCallback(VisibilityProperty, OnVisibilityChanged);
}

private void OnVisibilityChanged(DependencyObject sender, DependencyProperty dp)
{
// If the parent is a Segmented control with an EqualPanel,
// we need to invalidate measure to update the layout.
if ((this.Parent as Segmented)?.ItemsPanelRoot is EqualPanel panel)
Copy link
Member

Choose a reason for hiding this comment

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

Could it just be any panel still? I can't imagine this issue would be unique to just the Equal Panel? Also, if we just invalidate our own measure, shouldn't that re-trigger the parent panel anyway?

{
panel.InvalidateMeasure();
}
}

/// <inheritdoc/>
Expand Down
Loading