Skip to content

Commit 13b972a

Browse files
committed
Moved UserControl test paths down in priority
1 parent 96a6342 commit 13b972a

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

Microsoft.Toolkit.Uwp.UI/Extensions/Tree/LogicalTree.cs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -153,44 +153,46 @@ public static class LogicalTree
153153
}
154154
}
155155
}
156-
else if (element is UserControl userControl)
156+
else if (element is ContentControl contentControl)
157157
{
158-
if (userControl.Content is T result && predicate.Match(result))
158+
if (contentControl.Content is T result && predicate.Match(result))
159159
{
160160
return result;
161161
}
162162

163-
if (userControl.Content is FrameworkElement content)
163+
if (contentControl.Content is FrameworkElement content)
164164
{
165165
element = content;
166166

167167
goto Start;
168168
}
169169
}
170-
else if (element is ContentControl contentControl)
170+
else if (element is Border border)
171171
{
172-
if (contentControl.Content is T result && predicate.Match(result))
172+
if (border.Child is T result && predicate.Match(result))
173173
{
174174
return result;
175175
}
176176

177-
if (contentControl.Content is FrameworkElement content)
177+
if (border.Child is FrameworkElement child)
178178
{
179-
element = content;
179+
element = child;
180180

181181
goto Start;
182182
}
183183
}
184-
else if (element is Border border)
184+
else if (element is UserControl userControl)
185185
{
186-
if (border.Child is T result && predicate.Match(result))
186+
// We put UserControl right before the slower reflection fallback path as
187+
// this type is less likely to be used compared to the other ones above.
188+
if (userControl.Content is T result && predicate.Match(result))
187189
{
188190
return result;
189191
}
190192

191-
if (border.Child is FrameworkElement child)
193+
if (userControl.Content is FrameworkElement content)
192194
{
193-
element = child;
195+
element = content;
194196

195197
goto Start;
196198
}
@@ -348,9 +350,9 @@ public static IEnumerable<FrameworkElement> FindChildren(this FrameworkElement e
348350
}
349351
}
350352
}
351-
else if (element is UserControl userControl)
353+
else if (element is ContentControl contentControl)
352354
{
353-
if (userControl.Content is FrameworkElement content)
355+
if (contentControl.Content is FrameworkElement content)
354356
{
355357
yield return content;
356358

@@ -359,24 +361,24 @@ public static IEnumerable<FrameworkElement> FindChildren(this FrameworkElement e
359361
goto Start;
360362
}
361363
}
362-
else if (element is ContentControl contentControl)
364+
else if (element is Border border)
363365
{
364-
if (contentControl.Content is FrameworkElement content)
366+
if (border.Child is FrameworkElement child)
365367
{
366-
yield return content;
368+
yield return child;
367369

368-
element = content;
370+
element = child;
369371

370372
goto Start;
371373
}
372374
}
373-
else if (element is Border border)
375+
else if (element is UserControl userControl)
374376
{
375-
if (border.Child is FrameworkElement child)
377+
if (userControl.Content is FrameworkElement content)
376378
{
377-
yield return child;
379+
yield return content;
378380

379-
element = child;
381+
element = content;
380382

381383
goto Start;
382384
}

0 commit comments

Comments
 (0)