Skip to content

Commit 4cdefee

Browse files
Merge pull request #1307 from Microsoft/Dropshadow-Content
DropShadowPanel Content wireup size changed
2 parents 79da13f + a4e0e16 commit 4cdefee

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

Microsoft.Toolkit.Uwp.UI.Controls/DropShadowPanel/DropShadowPanel.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ public DropShadowPanel()
5050

5151
_dropShadow = compositor.CreateDropShadow();
5252
_shadowVisual.Shadow = _dropShadow;
53-
54-
SizeChanged += OnSizeChanged;
5553
}
5654
}
5755

@@ -77,6 +75,31 @@ protected override void OnApplyTemplate()
7775
base.OnApplyTemplate();
7876
}
7977

78+
protected override void OnContentChanged(object oldContent, object newContent)
79+
{
80+
if (oldContent != null)
81+
{
82+
var oldElement = oldContent as FrameworkElement;
83+
84+
if (oldElement != null)
85+
{
86+
oldElement.SizeChanged -= OnSizeChanged;
87+
}
88+
}
89+
90+
if (newContent != null)
91+
{
92+
var newElement = newContent as FrameworkElement;
93+
94+
if (newElement != null)
95+
{
96+
newElement.SizeChanged += OnSizeChanged;
97+
}
98+
}
99+
100+
base.OnContentChanged(oldContent, newContent);
101+
}
102+
80103
private void OnSizeChanged(object sender, SizeChangedEventArgs e)
81104
{
82105
UpdateShadowSize();

0 commit comments

Comments
 (0)