Unexpected items were obtained in a subclass of ItemsControl
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
- Clone https://github.com/GochenRyan/WinUISample
- Checkout commit a2089d3cdddd586a5eddff456d304fc3672aca02
- Set Layout as startup project
- insert a break point at https://github.com/GochenRyan/WinUISample/blob/a2089d3cdddd586a5eddff456d304fc3672aca02/WinUISample/Layout/Controls/RootDockControl.cs#L23
- Run
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
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 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 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.
@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.
@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.