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

Unexpected items were obtained in a subclass of ItemsControl

Open GochenRyan opened this issue 1 year ago • 2 comments

Describe the bug

I wrote a RootDockControl subclass of ItemsControl. But when I pass DocumentDock (its VisibleDockables) to it through binding, what it gets is Document (DocumentDock's VisibleDockables).

Steps to reproduce the bug

  1. Clone https://github.com/GochenRyan/WinUISample
  2. Checkout commit a2089d3cdddd586a5eddff456d304fc3672aca02
  3. Set Layout as startup project
  4. insert a break point at https://github.com/GochenRyan/WinUISample/blob/a2089d3cdddd586a5eddff456d304fc3672aca02/WinUISample/Layout/Controls/RootDockControl.cs#L23
  5. Run Snipaste_2024-05-20_23-58-57

Expected behavior

The item should be DocumentDock

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.5.3: 1.5.240428000

Windows version

Windows 11 (22H2): Build 22621

Additional context

No response

GochenRyan avatar May 20 '24 16:05 GochenRyan

I tested it to be an ownerType issue. I get the result I want when the ownerType of VisibleDockablesProperty is DocumentDock. Is there a good way to handle the ownerType of VisibleDockablesProperty in the inheritance chain?

GochenRyan avatar May 22 '24 10:05 GochenRyan

@GochenRyan I'm having trouble understanding the issue. can you explain a bit more/provide a repro project that is scoped to the problem you are facing?

ranjeshj avatar Jun 28 '24 17:06 ranjeshj

@ranjeshj I want to use the ContentTemplateSelector of ContentControl and the ItemTemplateSelector of ItemsControl to generate the corresponding custom controls step by step according to the node tree of xaml here:

<local1:DockControl>
    <models:RootDock>
        <models:RootDock.VisibleDockables>
            <models:DocumentDock>
                <models:DocumentDock.VisibleDockables>
                    <models:Document x:Name="Document1" Title="Program.cs">
                        <TextBlock Text="{Binding Title}"/>
                    </models:Document>
                    <!--<models:Document x:Name="Document2" Title="App.axaml">
                        <TextBlock Text="{Binding Title}"/>
                    </models:Document>-->
                </models:DocumentDock.VisibleDockables>
            </models:DocumentDock>
        </models:RootDock.VisibleDockables>
    </models:RootDock>
</local1:DockControl>

When creating a RootDockControl, its Items are not just the next level nodes.

GochenRyan avatar Jul 02 '24 03:07 GochenRyan

@ranjeshj Actually I have a solution. I created a new branch fix-containerdp and fixed this issue in commit 9b43b77802fdb0e097ce09c8f9e7aeefe27b43f8. In short, by putting the container dependency property at the last level of the inheritance chain. But I don't know why the container dependency property needs to be handled specially.

GochenRyan avatar Jul 02 '24 04:07 GochenRyan

@ranjeshj My fault. I misunderstood the usage of Collection-type dp. FYI: https://learn.microsoft.com/en-us/windows/uwp/xaml-platform/custom-dependency-properties#collection-type-dependency-properties.

GochenRyan avatar Jul 09 '24 04:07 GochenRyan