Skip to content

Commit

Permalink
Merge pull request #2910 from unoplatform/mergify/bp/release/beta/2.1…
Browse files Browse the repository at this point in the history
…/pr-2903

fix(elevatedview): Make sure the `ElevatedView` propagates its `TemplatedParent`. (bp #2903)
  • Loading branch information
jeromelaban authored Apr 3, 2020
2 parents fb215b2 + 98ed706 commit 22343e8
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/Uno.UI.Toolkit/ElevatedView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public sealed partial class ElevatedView : Control
public ElevatedView()
{
DefaultStyleKey = typeof(ElevatedView);

#if !NETFX_CORE
Loaded += (snd, evt) => SynchronizeContentTemplatedParent();
#endif
}

protected override void OnApplyTemplate()
Expand Down Expand Up @@ -104,6 +108,25 @@ public CornerRadius CornerRadius
get => (CornerRadius)GetValue(CornerRadiusProperty);
set => SetValue(CornerRadiusProperty, value);
}

protected internal override void OnTemplatedParentChanged(DependencyPropertyChangedEventArgs e)
{
base.OnTemplatedParentChanged(e);

// This is required to ensure that FrameworkElement.FindName can dig through the tree after
// the control has been created.
SynchronizeContentTemplatedParent();
}

private void SynchronizeContentTemplatedParent()
{
// Manual propagation of the templated parent to the content property
// until we get the propagation running properly
if (ElevatedContent is IFrameworkElement content)
{
content.TemplatedParent = this.TemplatedParent;
}
}
#endif

private static void OnChanged(DependencyObject snd, DependencyPropertyChangedEventArgs evt) => ((ElevatedView)snd).UpdateElevation();
Expand All @@ -115,6 +138,10 @@ private void UpdateElevation()
return; // not initialized yet
}

#if !NETFX_CORE
SynchronizeContentTemplatedParent();
#endif

if (Background == null)
{
this.SetElevationInternal(0, default);
Expand Down

0 comments on commit 22343e8

Please sign in to comment.