@@ -110,14 +110,50 @@ public static class LogicalTree
110
110
}
111
111
}
112
112
}
113
- else if ( element . GetContentControl ( ) is FrameworkElement contentControl )
113
+ else if ( element is UserControl userControl )
114
114
{
115
- if ( contentControl is T result && predicate ( result ) )
115
+ if ( userControl . Content is T result && predicate ( result ) )
116
116
{
117
117
return result ;
118
118
}
119
119
120
- return FindChild ( contentControl , predicate ) ;
120
+ if ( userControl . Content is FrameworkElement content )
121
+ {
122
+ return FindChild ( content , predicate ) ;
123
+ }
124
+ }
125
+ else if ( element is ContentControl contentControl )
126
+ {
127
+ if ( contentControl . Content is T result && predicate ( result ) )
128
+ {
129
+ return result ;
130
+ }
131
+
132
+ if ( contentControl . Content is FrameworkElement content )
133
+ {
134
+ return FindChild ( content , predicate ) ;
135
+ }
136
+ }
137
+ else if ( element is Border border )
138
+ {
139
+ if ( border . Child is T result && predicate ( result ) )
140
+ {
141
+ return result ;
142
+ }
143
+
144
+ if ( border . Child is FrameworkElement child )
145
+ {
146
+ return FindChild ( child , predicate ) ;
147
+ }
148
+ }
149
+ else if ( element . GetContentControl ( ) is FrameworkElement containedControl )
150
+ {
151
+ if ( containedControl is T result && predicate ( result ) )
152
+ {
153
+ return result ;
154
+ }
155
+
156
+ return FindChild ( containedControl , predicate ) ;
121
157
}
122
158
123
159
return null ;
@@ -179,14 +215,50 @@ public static class LogicalTree
179
215
}
180
216
}
181
217
}
182
- else if ( element . GetContentControl ( ) is FrameworkElement contentControl )
218
+ else if ( element is UserControl userControl )
219
+ {
220
+ if ( userControl . Content is T result && predicate ( result , state ) )
221
+ {
222
+ return result ;
223
+ }
224
+
225
+ if ( userControl . Content is FrameworkElement content )
226
+ {
227
+ return FindChild ( content , state , predicate ) ;
228
+ }
229
+ }
230
+ else if ( element is ContentControl contentControl )
231
+ {
232
+ if ( contentControl . Content is T result && predicate ( result , state ) )
233
+ {
234
+ return result ;
235
+ }
236
+
237
+ if ( contentControl . Content is FrameworkElement content )
238
+ {
239
+ return FindChild ( content , state , predicate ) ;
240
+ }
241
+ }
242
+ else if ( element is Border border )
243
+ {
244
+ if ( border . Child is T result && predicate ( result , state ) )
245
+ {
246
+ return result ;
247
+ }
248
+
249
+ if ( border . Child is FrameworkElement child )
250
+ {
251
+ return FindChild ( child , state , predicate ) ;
252
+ }
253
+ }
254
+ else if ( element . GetContentControl ( ) is FrameworkElement containedControl )
183
255
{
184
- if ( contentControl is T result && predicate ( result , state ) )
256
+ if ( containedControl is T result && predicate ( result , state ) )
185
257
{
186
258
return result ;
187
259
}
188
260
189
- return FindChild ( contentControl , state , predicate ) ;
261
+ return FindChild ( containedControl , state , predicate ) ;
190
262
}
191
263
192
264
return null ;
@@ -328,11 +400,47 @@ public static IEnumerable<FrameworkElement> FindChildren(this FrameworkElement e
328
400
}
329
401
}
330
402
}
331
- else if ( element . GetContentControl ( ) is FrameworkElement contentControl )
403
+ else if ( element is UserControl userControl )
404
+ {
405
+ if ( userControl . Content is FrameworkElement content )
406
+ {
407
+ yield return content ;
408
+
409
+ foreach ( FrameworkElement childOfContent in FindChildren ( content ) )
410
+ {
411
+ yield return childOfContent ;
412
+ }
413
+ }
414
+ }
415
+ else if ( element is ContentControl contentControl )
416
+ {
417
+ if ( contentControl . Content is FrameworkElement content )
418
+ {
419
+ yield return content ;
420
+
421
+ foreach ( FrameworkElement childOfContent in FindChildren ( content ) )
422
+ {
423
+ yield return childOfContent ;
424
+ }
425
+ }
426
+ }
427
+ else if ( element is Border border )
428
+ {
429
+ if ( border . Child is FrameworkElement child )
430
+ {
431
+ yield return child ;
432
+
433
+ foreach ( FrameworkElement childOfChild in FindChildren ( child ) )
434
+ {
435
+ yield return childOfChild ;
436
+ }
437
+ }
438
+ }
439
+ else if ( element . GetContentControl ( ) is FrameworkElement containedControl )
332
440
{
333
- yield return contentControl ;
441
+ yield return containedControl ;
334
442
335
- foreach ( FrameworkElement childOfChild in FindChildren ( contentControl ) )
443
+ foreach ( FrameworkElement childOfChild in FindChildren ( containedControl ) )
336
444
{
337
445
yield return childOfChild ;
338
446
}
0 commit comments