CommunityToolkit / Labs-Windows

A safe space to collaborate and engineer solutions from the prototyping stage all the way through polished finalized component for the Windows Community Toolkit.
Other
323 stars 44 forks source link

Segmented Control crash if StackPanel Orientation value is Horizontal #425

Closed WillyWoe closed 1 year ago

WillyWoe commented 1 year ago

Describe the bug

If StackPanel Orientation value is set to Vertical it works, but if is set to Horizontal the app crashes:

Xaml

<Window
    x:Class="LabsTests.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:LabsTests"
    xmlns:labs="using:CommunityToolkit.Labs.WinUI"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <StackPanel Orientation="Vertical"> <!--If Orientation value is Horizontal, the app crashes-->
        <labs:Segmented SelectedIndex="0"                        
                        SelectionMode="Single">
            <labs:SegmentedItem Content="Item 1">
                <labs:SegmentedItem.Icon>
                    <FontIcon Glyph="&#xEA3A;" />
                </labs:SegmentedItem.Icon>
            </labs:SegmentedItem>
            <labs:SegmentedItem Content="Item 2">
                <labs:SegmentedItem.Icon>
                    <FontIcon Glyph="&#xEA3A;" />
                </labs:SegmentedItem.Icon>
            </labs:SegmentedItem>
            <labs:SegmentedItem Content="Item 3 with a long label">
                <labs:SegmentedItem.Icon>
                    <FontIcon Glyph="&#xEA3A;" />
                </labs:SegmentedItem.Icon>
            </labs:SegmentedItem>
            <labs:SegmentedItem Content="Item 4">
                <labs:SegmentedItem.Icon>
                    <FontIcon Glyph="&#xEA3A;" />
                </labs:SegmentedItem.Icon>
            </labs:SegmentedItem>
        </labs:Segmented>
    </StackPanel>
</Window>

NuGet references

<PackageReference Include="CommunityToolkit.Labs.WinUI.SegmentedControl" Version="0.0.2" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.2.230118.102" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.1" />

Steps to reproduce

1. Create a new WinUI Desktop project.
3. Copy the xml above and use the NuGet references.
4. Set `StackPanel` Orientation value to Horizontal in the example above.
5. Run the app.

Expected behavior

Segmented Control should not crash if StackPanel Orientation is set to Horizontal.

Screenshots

No response

Code Platform

Windows Build Number

Other Windows Build number

Windows 10 22H2 Build 19045

App minimum and target SDK version

Other SDK version

No response

Visual Studio Version

2022

Visual Studio Build Number

No response

Device form factor

Desktop

Additional context

No response

Help us help you

No, I'm unable to contribute a solution.

michael-hawker commented 1 year ago

@WillyWoe I believe this is what will be fixed by #416? @niels9001 do you agree? Did we have an issue for this already, or should we just use this one?

niels9001 commented 1 year ago

@WillyWoe Thanks for flagging this!

@michael-hawker Yep, just tested - and #416 resolves this bug. I think it's very similar (the width is unknown, hence the crash) so let's use this issue!