-
Notifications
You must be signed in to change notification settings - Fork 800
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
In the documentation for the Pivot control, there is an example that decrements SelectedIndex to navigate to the previous item:
private void BackButton_Click(object sender, RoutedEventArgs e)
{
if (rootPivot.SelectedIndex > 0)
{
// If not at the first item, go back to the previous one.
rootPivot.SelectedIndex -= 1;
}
else
{
// The first PivotItem is selected, so loop around to the last item.
rootPivot.SelectedIndex = rootPivot.Items.Count-1;
}
}However, in actual usage, when this operation results in SelectedIndex being set to -1, a COMException is always thrown at runtime.
Why is this important?
This behavior directly contradicts the official documentation and can easily mislead developers.
Steps to reproduce the bug
- Create a new WinUI 3 project.
- Add the following code:
<Grid>
<Pivot x:Name="pivot">
<PivotItem Header="1" />
<PivotItem Header="2" />
<PivotItem Header="3" />
</Pivot>
<Button Click="Button_Click" Content="Click" />
</Grid>private void Button_Click(object sender, RoutedEventArgs e)
{
if (pivot.SelectedIndex > 0)
{
pivot.SelectedIndex = -1;
}
else
{
pivot.SelectedIndex++;
}
}- Run and click the button.
Actual behavior
A COMException is thrown when SelectedIndex becomes -1.
Expected behavior
- Setting
SelectedIndexto-1should be handled gracefully (for example, clamped to 0 or ignored).
OR
- The documentation example should clearly state that
SelectedIndexmust be validated and must not be set to-1, and provide a corrected sample implementation.
Screenshots
NuGet package version
WinUI 3 - Windows App SDK 1.8.3: 1.8.251106002
Windows version
Windows 11 (24H2): Build 26100
Additional context
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working