Skip to content

Commit 57b7d52

Browse files
Add ContentPresenter to Logical Tree helpers
Helps get down through SwitchPresenter. (Up doesn't work as Parent is not being set, WinUI bug?)
1 parent 0feca9c commit 57b7d52

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Microsoft.Toolkit.Uwp.UI/Extensions/FrameworkElement/FrameworkElementExtensions.LogicalTree.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,23 @@ public static partial class FrameworkElementExtensions
179179
goto Start;
180180
}
181181
}
182+
else if (element is ContentPresenter contentPresenter)
183+
{
184+
// Sometimes ContentPresenters are used in control templates instead of ContentControls
185+
// Therefore we should still check if it's Content is a FrameworkElement and match.
186+
// This also makes this work for SwitchPresenter.
187+
if (contentPresenter.Content is T result && predicate.Match(result))
188+
{
189+
return result;
190+
}
191+
192+
if (contentPresenter.Content is FrameworkElement content)
193+
{
194+
element = content;
195+
196+
goto Start;
197+
}
198+
}
182199
else if (element is UserControl userControl)
183200
{
184201
// We put UserControl right before the slower reflection fallback path as
@@ -370,6 +387,17 @@ public static IEnumerable<FrameworkElement> FindChildren(this FrameworkElement e
370387
goto Start;
371388
}
372389
}
390+
else if (element is ContentPresenter contentPresenter)
391+
{
392+
if (contentPresenter.Content is FrameworkElement content)
393+
{
394+
yield return content;
395+
396+
element = content;
397+
398+
goto Start;
399+
}
400+
}
373401
else if (element is UserControl userControl)
374402
{
375403
if (userControl.Content is FrameworkElement content)

0 commit comments

Comments
 (0)