-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Description
When a ContentView's BindingContext is set in code-behind after InitializeComponent(), a BindableLayout.ItemsSource="{Binding Items}" inside that ContentView only renders the first item from an ObservableCollection on Mac Catalyst. The collection reports the correct count, but only 1 of N items appears in the visual tree.
Steps to Reproduce
- Clone the repro: https://github.com/rmarinho/bindable-layout-repro
- Run on Mac Catalyst:
dotnet build -f net11.0-maccatalyst -t:Run - Observe the "Items from BindableLayout" section — only 1 item renders instead of 5
Repro structure:
ItemListView.xaml— AContentViewwithBindableLayout.ItemsSource="{Binding Items}"and anItemTemplateItemListViewModel.cs— HasObservableCollection<string>with 5 items in the collection initializerMainPage.xaml.cs— SetsBuggyList.BindingContext = viewModelafterInitializeComponent()
Expected Behavior
All 5 items from the ObservableCollection should render in the VerticalStackLayout via BindableLayout.
The {Binding Items.Count, StringFormat='Total items: {0}'} label correctly shows "Total items: 5", confirming the binding resolves and the collection has all items — but only 1 item is rendered.
Actual Behavior
Only the first item ("Item 1 - Apple") renders. The remaining 4 items are not present in the visual tree.
Additionally:
- Dynamically adding items to the
ObservableCollectionafter initial load also does not render - The binding itself resolves (proven by
Items.Countbinding showing correct value) - The issue appears specific to
BindableLayoutinside aContentViewwhenBindingContextis set post-initialization
Workaround
Call BindableLayout.SetItemsSource() directly in code-behind instead of using XAML binding:
// Instead of: BuggyList.BindingContext = viewModel;
// (which relies on BindableLayout.ItemsSource="{Binding Items}" in XAML)
// Use:
BindableLayout.SetItemsSource(myLayout, viewModel.Items);The repro project includes both the buggy scenario (blue items, only 1 renders) and the workaround (green items, all 5 render correctly).
Reproduction Link
https://github.com/rmarinho/bindable-layout-repro
Version with bug
10.0.41 SR1 / 11.0-preview
Is this a regression from previous behavior?
Unknown — first encountered on Mac Catalyst with .NET 10
Last version that worked well
No response
Affected platforms
macOS (Mac Catalyst)
Affected platform versions
macOS 15.x (Sequoia)
Did you find any workaround?
Yes — call BindableLayout.SetItemsSource(layout, collection) directly in code-behind instead of using XAML BindableLayout.ItemsSource="{Binding ...}".
Relevant log output
No response