microsoft-ui-xaml icon indicating copy to clipboard operation
microsoft-ui-xaml copied to clipboard

Unexpected results when nesting binding to ItemsControl

Open GochenRyan opened this issue 1 year ago • 3 comments

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

  1. Clone https://github.com/GochenRyan/WinUISample.git
  2. Checkout commit 50541ea5f2c3a1976c5b29753ccdadfe383cc30c
  3. Set NestedBinding as startup project
  4. Insert a break point at https://github.com/GochenRyan/WinUISample/blob/f1f371e780fe133d1bb6ade33efccf5546ac2a42/WinUISample/NestedBinding/ItemsControl1Selector.cs#L18
  5. 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

GochenRyan avatar Jun 11 '24 11:06 GochenRyan

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:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

github-actions[bot] avatar Jun 11 '24 11:06 github-actions[bot]

I fixed the infinite loop issue (commit c6059d3ee9cd99c11b2d8a488a6bc9aab14b8e21),but it still did not achieve the expected results. It ignored <local:ItemsModel1 x:Name="ItemsModel1"> image

GochenRyan avatar Jun 12 '24 08:06 GochenRyan

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.

GochenRyan avatar Jun 13 '24 09:06 GochenRyan

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

GochenRyan avatar Jul 08 '24 10:07 GochenRyan

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

GochenRyan avatar Jul 08 '24 10:07 GochenRyan

So how can we fix this bug, it still happens

leohu1 avatar Jul 25 '24 15:07 leohu1