Repository navigation
Closed as not planned
Labels
difficulty/challenging 🤯Categorizes an issue for which the difficulty level is reachable with internals understandingkind/bugSomething isn't workingplatform/android 🤖Categorizes an issue or PR as relevant to the Android platformplatform/ios 🍎Categorizes an issue or PR as relevant to the iOS platformproject/layout 🧱Categorizes an issue or PR as relevant to layouting and containers (Measure/Arrange, Collections,..)project/navigation-lifecycle 🧬Categorizes an issue or PR as relevant to the navigation and lifecycle (NavigationView, AppBar, ...)
Description
I'm submitting a...
- Bug report (I searched for similar issues and did not find one)
Current behavior
If we instantiate a control and set the Template property, then this template is applied immediately (which leads to invoke the OnApplyTemplate in the control).
Expected behavior
On Windows the template of a control is being applied only when this control is in the visual tree and either we explicitly invoke the ApplyTemplate method, or we wait for the first measure pass.
Note: To get the full behavior of windows, we should be able to do:
var myControl = new MyControl { Template = _myControlTemplate };
_panelInTheVisualTree.Children.Add(myControl); // Template was not applied yet
myControl.ApplyTemplate(); // Will invoke `OnApplyTemplate` synchronously and returns `true`
_panelInTheVisualTree.Children.Remove(myControl); // `myControl` was not measuredBut if the panel is not in the visual tree, myControl.ApplyTemplate() should not do anything and returns false
Minimal reproduction of the problem with instructions
var myControl = new MyControl { Template = _myControlTemplate };Environment
Nuget Package: Uno.UI
Package Version(s): 1.25.0-dev.42
Affected platform(s):
- [x] iOS
- [x] Android
- [?] WebAssembly
- [ ] Windows
- [ ] Build tasks
Visual Studio : _Irrelevant_
Relevant plugins: _Irrelevant_
Reacted by yowl
Metadata
Metadata
Assignees
Labels
difficulty/challenging 🤯Categorizes an issue for which the difficulty level is reachable with internals understandingkind/bugSomething isn't workingplatform/android 🤖Categorizes an issue or PR as relevant to the Android platformplatform/ios 🍎Categorizes an issue or PR as relevant to the iOS platformproject/layout 🧱Categorizes an issue or PR as relevant to layouting and containers (Measure/Arrange, Collections,..)project/navigation-lifecycle 🧬Categorizes an issue or PR as relevant to the navigation and lifecycle (NavigationView, AppBar, ...)
Activity
dr1rrb commentedon Sep 12, 2018
This got mitigated by #192, but it's still not properly aligned with UWP.
davidjohnoliver commentedon Sep 27, 2018
ApplyTemplate()doesn't require the view to be in the visual tree, it just requiresTemplateto be non-null. If theControlhas an implicit style then itsTemplatewill be null on UWP until it's in the visual tree because theStylecan't be resolved until that point. The root cause then is #119.For now the best workaround is to set
FeatureConfiguration.Control.UseLegacyLazyApplyTemplate = true.peternary commentedon Aug 6, 2019
The specific issue we're encountering involves a custom control that wraps a ListView and accepts a DataTemplateSelector as a wrapper but includes a default DataTemplateSelector. By the time we have received the DataTemplateSelector the ListView has already been rendered using the default DataTemplateSelector.
dr1rrb commentedon Jun 19, 2020
This is causing some troubles again with this:
If in the callback of the
DisplayTemplatePropertyyou do something likeTemplate = DisplayTemplate, then theOnApplyTemplatewill be invoked twice (once with theDisplayTemplateand a second time withe the template defined in the style for theTemplateproperty).On Windows the template is applied only on first measure, so the
OnApplyTemplateis invoked only once (with theDisplayTemplate, but this is certainly due to #3398)1 remaining item
Youssef1313 commentedon Nov 9, 2023
This was causing an issue in one of the tests that I worked around in #14368.
For my case though, the issue is that control templates are not applied on the first measure pass, not that they are applied early.
I added some code comments in #14368 that mentions some of the relevant parts of WinUI source code.
[-]Control templates are applied too early[/-][+][Non-Skia] Control templates are applied too early[/+][-][Non-Skia] Control templates are applied too early[/-][+][Android, iOS] Control templates are applied too early[/+]Youssef1313 commentedon Oct 6, 2024
This will be easily fixable after #18261 is merged
MartinZikmund commentedon Jul 15, 2025
This is only relevant to native renderer, closing. CC @Jen-Uno
Youssef1313 commentedon Jul 15, 2025
@MartinZikmund I'm curious. Are native renderers removed completely? Or they are there but are no longer a supported scenario and exists only for backcompat?
github-actions commentedon May 5, 2026
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or feature requests.