@@ -153,44 +153,44 @@ public static partial class FrameworkElementExtensions
153
153
}
154
154
else if ( element is ContentControl contentControl )
155
155
{
156
- if ( contentControl . Content is T result && predicate . Match ( result ) )
157
- {
158
- return result ;
159
- }
160
-
161
156
if ( contentControl . Content is FrameworkElement content )
162
157
{
158
+ if ( content is T result && predicate . Match ( result ) )
159
+ {
160
+ return result ;
161
+ }
162
+
163
163
element = content ;
164
164
165
165
goto Start ;
166
166
}
167
167
}
168
168
else if ( element is Border border )
169
169
{
170
- if ( border . Child is T result && predicate . Match ( result ) )
171
- {
172
- return result ;
173
- }
174
-
175
170
if ( border . Child is FrameworkElement child )
176
171
{
172
+ if ( child is T result && predicate . Match ( result ) )
173
+ {
174
+ return result ;
175
+ }
176
+
177
177
element = child ;
178
178
179
179
goto Start ;
180
180
}
181
181
}
182
182
else if ( element is ContentPresenter contentPresenter )
183
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 .
184
+ // Sometimes ContentPresenter is used in control templates instead of ContentControl,
185
+ // therefore we should still check if its Content is a matching FrameworkElement instance .
186
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
187
if ( contentPresenter . Content is FrameworkElement content )
193
188
{
189
+ if ( content is T result && predicate . Match ( result ) )
190
+ {
191
+ return result ;
192
+ }
193
+
194
194
element = content ;
195
195
196
196
goto Start ;
@@ -200,13 +200,13 @@ public static partial class FrameworkElementExtensions
200
200
{
201
201
// We put UserControl right before the slower reflection fallback path as
202
202
// this type is less likely to be used compared to the other ones above.
203
- if ( userControl . Content is T result && predicate . Match ( result ) )
204
- {
205
- return result ;
206
- }
207
-
208
203
if ( userControl . Content is FrameworkElement content )
209
204
{
205
+ if ( content is T result && predicate . Match ( result ) )
206
+ {
207
+ return result ;
208
+ }
209
+
210
210
element = content ;
211
211
212
212
goto Start ;
0 commit comments