Repository navigation
fix(control): Re-measure when Template changes - #26556
MartinZikmund merged 2 commits into
Conversation
Control.Template was missing the AffectsMeasure flag it has in WinUI, so replacing the template of a loaded control removed the old template root but never scheduled a measure pass, and the new template was not applied until something else invalidated the control. Fixes unoplatform#25217
|
Azure Pipelines: 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
This pull request is merged. |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. |
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 247500 found UI Test snapshots differences: Details
|
MartinZikmund
left a comment
There was a problem hiding this comment.
@chmolto thanks for tracking this one down, and for cleaning up that stale SetUpdateControlTemplate comment while you were at it!
The Control.cs change looks right to me:
- WinUI parity:
Control_TemplatecarriesMetaDataPropertyInfoFlags::AffectMeasureindxaml/xcp/components/metadata/StaticMetadata.g.cpp, andCControl::SetValue(dxaml/xcp/core/core/elements/Control.cpp) only removes the old template child. The next measure then re-applies the template throughCFrameworkElement::ApplyTemplate, which is guarded byHasTemplateChild(). With this change Uno does the same. - Startup cost: nothing extra happens there. Elements start out with
MeasureDirtyset (DEFAULT_STARTING_LAYOUTFLAGS), so a Template set through a Style before the first measure makesInvalidateMeasure()return straight away. The template is still applied once, becauseApplyTemplateis guarded byHasTemplateChild(). Re-setting the same template instance doesn't raise a change at all.
One thing needs fixing before merge: the new test fails on the native WinUI lane (Tests - WinAppSDK Runtime Tests, build 247500). It is the only failure in that run:
Assert.AreEqual failed. Expected:<1>. Actual:<0>. ... The new template was not applied
at Given_Control.When_Template_Changed_After_Loaded()
See the inline comment. The ~225/264 screenshot diffs are the usual baseline noise (other PRs from today show the same counts), so you can ignore those.
With a null Template, WinUI's ContentControl creates default visuals for string content, so the Button round trip did not behave the same on the native WinUI lane. Use a non-content control and switch to a different template instead.
|
Pushed the updated test in b871055. Could you kick off the pipeline again when you have a moment, so the WinAppSDK lane can confirm it? |
MartinZikmund
left a comment
There was a problem hiding this comment.
@chmolto thanks! Swapping to a plain Control with two distinct templates sidesteps the ContentControl default-visuals difference on WinUI, and the explicit 40 -> 60 width check now proves the second template was really applied and measured. Looks good to me, pending the WinAppSDK lane confirming it on the next run.
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. |
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 247851 found UI Test snapshots differences: Details
|
|
🎉 Congratulations on getting your very first pull request merged into Uno Platform! This is a huge milestone — you are now officially part of the community of contributors helping shape the future of cross-platform .NET development, and your code will reach developers and apps all over the world. 🌍 |

GitHub Issue: closes #25217
PR Type:
Bugfix
What changed?
Setting
Templateon a control that is already loaded left the control blank.OnTemplateChangedremoves the old template root, butTemplatePropertywas registered withoutAffectsMeasure. Nothing scheduled a measure pass, soApplyTemplatenever ran for the new template. A comment said the flag was applied conditionally inSetUpdateControlTemplate, but that method no longer exists.Control.TemplatePropertynow hasAffectsMeasure. This matches WinUI, whereControl_Templateis registered withAffectMeasure, and matches howContentControl.ContentTemplateis already declared here.I added
Given_Control.When_Template_Changed_After_Loaded, which is the repro from the issue. It fails on master because the button has no children after the template is restored, and passes with this change. I ran the runtime tests on Skia Desktop (Win32) only. Given_Control, Given_Button, Given_ContentControl and Given_Style all pass. A wider subset of 13 control/layout test classes gave the same results with and without the change, apart from the new test.PR Checklist
Screenshots Compare Test Runresults. Will check once the pipeline has run on this PR.