unoplatform / uno.toolkit.ui

A set of custom controls for the WinUI and the Uno Platform not offered out of the box by WinUI, such as Card, TabBar, NavigationBar, etc.
https://platform.uno/
MIT License
81 stars 26 forks source link

TabBar nests TabBarItems when being set as ItemTemplate's root #1129

Open kazo0 opened 2 months ago

kazo0 commented 2 months ago

With the following XAML

<utu:TabBar SelectedIndex="3"
            ItemsSource="{Binding Data.Items}"
            Style="{StaticResource TopTabBarStyle}">
    <utu:TabBar.ItemTemplate>
        <DataTemplate>
            <utu:TabBarItem Background="Red" Content="Content" />
        </DataTemplate>
    </utu:TabBar.ItemTemplate>
</utu:TabBar>

We should be seeing this:

image

Instead, we are seeing that that TabBar now contains TabBarItems that contain the red TabBarItem as it's content:

image
Xiaoy312 commented 2 months ago

ChipGroup\Chip suffers the same problem

Both ChipGroup and TabBar inherits from ItemsControl, and both override GetContainerForItemOverride+IsItemItsOwnContainerOverride. This handles the case where the Items or ItemsSource contains the proper type for its item "container". However, it does not support the case where the supposed "container" is coming from the result of ItemTemplate.

That said, ListView and ListViewItem works... both on Windows and Uno somehow... On Uno, this is done via ItemsControl::GetRootOfItemTemplateAsContainer implemented in Selector. It is unclear how Windows is handling this..?