Skip to content

Commit

Permalink
chore: added explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoy312 committed Aug 24, 2020
1 parent b680cff commit 894eaf4
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/Uno.UI/UI/Xaml/Controls/ContentPresenter/ContentPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -701,13 +701,23 @@ private void SynchronizeContentTemplatedParent()
{
if (_contentTemplateRoot is IFrameworkElement binder)
{
var templatedParent = _contentTemplateRoot is ImplicitTextBlock
? this // ImplicitTextBlock is a special case that requires its TemplatedParent to be the ContentPresenter
: !SynchronizeContentWithOuterTemplatedParent && _dataTemplateUsedLastUpdate == null
? this.TemplatedParent
: (this.TemplatedParent as IFrameworkElement)?.TemplatedParent;
binder.TemplatedParent = FindTemplatedParent();

binder.TemplatedParent = templatedParent;
object FindTemplatedParent()
{
// ImplicitTextBlock is a special case that requires its TemplatedParent to be the ContentPresenter
if (_contentTemplateRoot is ImplicitTextBlock) return this;

// Sometimes when content is a child view defined in the xaml, the direct TemplatedParent should be used,
// but only if the content hasnt been overwritten yet. If the content has been overwritten,
// either ImplicitTextBlock or the DataTemplate (requiring the outter TemplatedParent) would has been used.
if (!SynchronizeContentWithOuterTemplatedParent && _dataTemplateUsedLastUpdate == null)
{
return this.TemplatedParent;
}

return (this.TemplatedParent as IFrameworkElement)?.TemplatedParent;
}
}
else if (_contentTemplateRoot is DependencyObject dependencyObject)
{
Expand Down

0 comments on commit 894eaf4

Please sign in to comment.