Unexpected results when nesting binding to ItemsControl
Describe the bug
When I use nested models to bind and generate new ItemsControl subclass objects, it is like this:
<local:Model1 x:Name="Mode11111" Text="11111"/>
<local:ItemsModel1 x:Name="ItemsModel1">
<local:Model1 x:Name="Mode22222" Text="22222"/>
<local:Model1 x:Name="Mode33333" Text="33333"/>
<local:ItemsModel1 x:Name="ItemsModel2">
<local:Model1 x:Name="Mode44444" Text="44444"/>
</local:ItemsModel1>
</local:ItemsModel1>
<local:Model1 x:Name="Mode55555" Text="55555"/>
--> CustomItemsControl1(itemsControl) --ModelControl1(Control) --ModelControl1(Control) --CustomItemsControl1(itemsControl) ----ModelControl1(Control) --ModelControl1(Control)
This creates an infinite loop. What is the correct way to play?
Steps to reproduce the bug
- Clone https://github.com/GochenRyan/WinUISample.git
- Checkout commit 50541ea5f2c3a1976c5b29753ccdadfe383cc30c
- Set NestedBinding as startup project
- Insert a break point at https://github.com/GochenRyan/WinUISample/blob/f1f371e780fe133d1bb6ade33efccf5546ac2a42/WinUISample/NestedBinding/ItemsControl1Selector.cs#L18
- Run
Expected behavior
<local:Model1 x:Name="Mode11111" Text="11111"/>
<local:ItemsModel1 x:Name="ItemsModel1">
<local:Model1 x:Name="Mode22222" Text="22222"/>
<local:Model1 x:Name="Mode33333" Text="33333"/>
<local:ItemsModel1 x:Name="ItemsModel2">
<local:Model1 x:Name="Mode44444" Text="44444"/>
</local:ItemsModel1>
</local:ItemsModel1>
<local:Model1 x:Name="Mode55555" Text="55555"/>
--> CustomItemsControl1(itemsControl) --ModelControl1(Control) --ModelControl1(Control) --CustomItemsControl1(itemsControl) ----ModelControl1(Control) --ModelControl1(Control)
Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.5.3: 1.5.240428000
Windows version
Windows Insider Build (xxxxx)
Additional context
No response
Hi I'm an AI powered bot that finds similar issues based off the issue title.
Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one. Thank you!
Open similar issues:
- Binding not triggered from nested UserControl (#7298), similarity score: 0.76
Closed similar issues:
- Binding can cause Catastrophic Failures (#6612), similarity score: 0.73
- x:Bind and ItemsControl behaves weirdly with null values (#2614), similarity score: 0.71
- Binding using a specified source fails (#9375), similarity score: 0.71
- WinUI 3: x:Bind codegen is broken and produce infinite setter calling while using with TwoWay mode (#8441), similarity score: 0.71
Note: You can give me feedback by thumbs upping or thumbs downing this comment.
I fixed the infinite loop issue (commit c6059d3ee9cd99c11b2d8a488a6bc9aab14b8e21),but it still did not achieve the expected results. It ignored <local:ItemsModel1 x:Name="ItemsModel1">
I debugged the WinUI source code and found that it was a binding problem with ItemsSource. I fixed it on commit 6551175f5d312bd4860b5c2ec062a2b71409d5a3. I want to know why <local:CustomItemsControl1 ItemsSource="{Binding ItemModes, Mode=OneWay}"/> has problems and how to bind correctly.
I shouldn't remove static on commit c6059d3ee9cd99c11b2d8a488a6bc9aab14b8e21. FYI: https://learn.microsoft.com/en-us/windows/uwp/xaml-platform/custom-dependency-properties#collection-type-dependency-properties
And WinUI3 do not support a Binding usage for Setter.Value. So I need to set value in code. FYI: https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.setter?view=winrt-26100&redirectedfrom=MSDN#migration-notes
So how can we fix this bug, it still happens