Comments (7)
Your sample project has 2 problems.
- You are using x:DataType in a ResourceDictionary that does not have a code-behind file
- You have a self-referential infinite loop of ContentTemplateSelector, as RootControl uses a selector that can select it
Getting rid of the infinite loop and doing this works:
<?xml version="1.0" encoding="utf-8" ?>
<Window
x:Class="DockToy.MainWindow"
xmlns:controls="using:DockToy.controls"
xmlns:local="using:DockToy"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Page>
<Page.Resources>
<ResourceDictionary
xmlns:local="using:DockToy"
xmlns:models="using:DockToy.models"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<DataTemplate x:Key="RootDockTemplate" x:DataType="models:IRoot">
<local:RootControl Content="{x:Bind Content}" />
</DataTemplate>
<DataTemplate x:Key="DocumentDockTemplate" x:DataType="models:IDocument">
<local:DocumentControl Content="{x:Bind Content}" />
</DataTemplate>
<local:DockTemplateSelector
x:Key="DockControlSelector"
DocumnentDockTemplate="{StaticResource DocumentDockTemplate}"
RootDockTemplate="{StaticResource RootDockTemplate}" />
</ResourceDictionary>
</Page.Resources>
<local:DockControl ContentTemplateSelector="{StaticResource DockControlSelector}">
<controls:RootDock>
<controls:DocumentDock>
<TextBlock Text="I am a TextBlock" />
</controls:DocumentDock>
</controls:RootDock>
</local:DockControl>
</Page>
</Window>
Note that I used x:Bind here because as it has better performance, but Binding can be used if required.
Also note that a ContentControl, like UserControl, has special requirements on resource lookup:
from microsoft-ui-xaml.
Let us know if the suggestions don't work for you.
from microsoft-ui-xaml.
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:
- x:DataType doesn't work with nested types from other assemblies (#3238), similarity score: 0.73
- x:DataType="x:String" in DataTemplate of a ListView gives namespace issue (#6088), similarity score: 0.70
Closed similar issues:
- WinUI3 C++/WinRT - error when I create a DataTemplate Selector. (#7542), similarity score: 0.71
Note: You can give me feedback by thumbs upping or thumbs downing this comment.
from microsoft-ui-xaml.
Thanks for the suggestion. While @kmgallahan recommendation is indeed effective, it doesn't align with the specific requirements I aim to address. In fact, I intend to create a WinUI Class Library, so ultimately, I won't have a Window
.
Regarding the first problem, placing DataTemplates
under ResourceDictionary
is intended for inclusion in the MergedDictionaries
section of app.xaml for sharing purposes. By setting ContentTemplateSelector
on the subclass of ContentControl
, for each Model object in the node tree Dock-RootDock-DocumentDock, DockControlSelector
helps it find the corresponding control.
As for the second problem, to be honest, I haven't quite grasped it. Could you please provide further clarification on how I can replicate it? I've attempted to by placing breakpoints in SelectTemplateCore, but I haven't observed an infinite loop.
from microsoft-ui-xaml.
<local:DockControl ContentTemplateSelector="{StaticResource DockControlSelector}">
<controls:RootDock>
<controls:DocumentDock>
<TextBlock Text="I am a TextBlock" />
</controls:DocumentDock>
</controls:RootDock>
</local:DockControl>
If I write it this way, I can only set the control corresponding to RootDock
, and subsequent child nodes cannot be processed.
from microsoft-ui-xaml.
Here in RootControl you state you want DockControlSelector to be used to choose its content:
And here DockControlSelector states it can pick RootControl to be the content:
from microsoft-ui-xaml.
Maybe I should create a new control to apply the selector to all nodes in its content
from microsoft-ui-xaml.
Related Issues (20)
- Wrong cursor displayed in Flyouts (no I-Beam in TextBox) HOT 2
- PipsPager keyboard navigation past first or last pip HOT 3
- Proposal: Method Based Administrator elevation (MSIX Package)
- When dragging and dropping ListView items, use `e.Data.SetDataProvider (StandardDataFormats. StorageItems, MyDataProviderHandle)` ; Unable to implement delayed data provision. HOT 1
- x:Bind with Mode=OneTime triggers multiple times HOT 2
- Focus does not move into the frame after navigating to one from a navigation view. HOT 2
- Setting true to NavigationFailedEventArgs.Handled is not respected
- Component Xaml file missing from app directory HOT 4
- Can not Build Project due to error message APPX110 Payload contains two or more files with the same destination path '.pdb'. HOT 4
- The Print UI dialogue is not shown on the Windows platform when the "EntryPoint" is set as "Windows.PartialTrustApplication" in Package.appxmanifest. HOT 2
- The first time "microsoft." is typed into a TextBox control, it will be capitalized for no reason HOT 4
- Multiple x:Bind to Name fails to build HOT 4
- While scrolling through the rows in the DataGrid, the value of the ComboBox element in the DataGridTemplateColumn CellTemplate is not updated correctly HOT 2
- Scrolling through very large number of items in ItemsRepeater + virtualized Layout + ScrollView causes blank frames HOT 2
- Command Bar - Issue with the Z - Index flow when "More Options" flyout is open. HOT 1
- Unexpected items were obtained in a subclass of ItemsControl HOT 1
- [ListView] The app crash when try to use the right click during a reorder operation. HOT 2
- WinUI 3 Acrylic effect not working properly over MediaPlayerElement HOT 2
- Dragging a file from Explorer over top of a WebView2 in the application window will launch another process HOT 3
- Proposal: Improve exception message for incorrect bound type using x:DataType
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from microsoft-ui-xaml.