-
Notifications
You must be signed in to change notification settings - Fork 721
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9fa1641
commit a589451
Showing
9 changed files
with
259 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/Uno.UI/UI/Xaml/Controls/Control/Control.nonlifecycle.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#if !UNO_HAS_ENHANCED_LIFECYCLE | ||
namespace Microsoft.UI.Xaml.Controls; | ||
|
||
partial class Control | ||
{ | ||
private bool _updateTemplate; | ||
|
||
/// <summary> | ||
/// Will be set to Template when it is applied | ||
/// </summary> | ||
private ControlTemplate _controlTemplateUsedLastUpdate; | ||
|
||
private bool _applyTemplateShouldBeInvoked; | ||
|
||
/// <summary> | ||
/// Defines a method that will request the update of the control's template and request layout update. | ||
/// </summary> | ||
/// <param name="forceUpdate">If true, forces an update even if the control has no parent.</param> | ||
internal void SetUpdateControlTemplate(bool forceUpdate = false) | ||
{ | ||
if ( | ||
!FeatureConfiguration.Control.UseLegacyLazyApplyTemplate || | ||
forceUpdate || | ||
this.HasParent() || | ||
CanCreateTemplateWithoutParent | ||
) | ||
{ | ||
UpdateTemplate(); | ||
this.InvalidateMeasure(); | ||
} | ||
} | ||
|
||
internal void TryCallOnApplyTemplate() | ||
{ | ||
if (_applyTemplateShouldBeInvoked) | ||
{ | ||
_applyTemplateShouldBeInvoked = false; | ||
OnApplyTemplate(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Loads the relevant control template so that its parts can be referenced. | ||
/// </summary> | ||
/// <returns>A value that indicates whether the visual tree was rebuilt by this call. True if the tree was rebuilt; false if the previous visual tree was retained.</returns> | ||
public bool ApplyTemplate() | ||
{ | ||
var currentTemplateRoot = _templatedRoot; | ||
SetUpdateControlTemplate(forceUpdate: true); | ||
|
||
// When .ApplyTemplate is called manually, we should not defer the call to OnApplyTemplate | ||
TryCallOnApplyTemplate(); | ||
|
||
return currentTemplateRoot != _templatedRoot; | ||
} | ||
|
||
private void UpdateTemplate() | ||
{ | ||
// If TemplatedRoot is null, it must be updated even if the templates haven't changed | ||
if (TemplatedRoot == null) | ||
{ | ||
_controlTemplateUsedLastUpdate = null; | ||
} | ||
|
||
if (_updateTemplate && !object.Equals(Template, _controlTemplateUsedLastUpdate)) | ||
{ | ||
_controlTemplateUsedLastUpdate = Template; | ||
|
||
if (Template != null) | ||
{ | ||
TemplatedRoot = Template.LoadContentCached(); | ||
} | ||
else | ||
{ | ||
TemplatedRoot = null; | ||
} | ||
|
||
_updateTemplate = false; | ||
} | ||
} | ||
} | ||
#endif |
Oops, something went wrong.