File tree Expand file tree Collapse file tree 2 files changed +25
-14
lines changed
Avalonia.Controls/Automation/Peers
Windows/Avalonia.Win32/Automation Expand file tree Collapse file tree 2 files changed +25
-14
lines changed Original file line number Diff line number Diff line change @@ -115,9 +115,14 @@ public abstract class AutomationPeer
115
115
/// <summary>
116
116
/// Gets the <see cref="AutomationPeer"/> that is the parent of this <see cref="AutomationPeer"/>.
117
117
/// </summary>
118
- /// <returns></returns>
119
118
public AutomationPeer ? GetParent ( ) => GetParentCore ( ) ;
120
119
120
+ /// <summary>
121
+ /// Gets the <see cref="AutomationPeer"/> that is the root of this <see cref="AutomationPeer"/>'s
122
+ /// visual tree.
123
+ /// </summary>
124
+ public AutomationPeer ? GetVisualRoot ( ) => GetVisualRootCore ( ) ;
125
+
121
126
/// <summary>
122
127
/// Gets a value that indicates whether the element that is associated with this automation
123
128
/// peer currently has keyboard focus.
@@ -247,6 +252,22 @@ protected virtual AutomationControlType GetControlTypeOverrideCore()
247
252
return GetAutomationControlTypeCore ( ) ;
248
253
}
249
254
255
+ protected virtual AutomationPeer ? GetVisualRootCore ( )
256
+ {
257
+ var parent = GetParent ( ) ;
258
+
259
+ while ( parent != null )
260
+ {
261
+ var nextParent = parent . GetParent ( ) ;
262
+ if ( nextParent == null )
263
+ return parent ;
264
+ parent = nextParent ;
265
+ }
266
+
267
+ return null ;
268
+ }
269
+
270
+
250
271
protected virtual bool IsContentElementOverrideCore ( )
251
272
{
252
273
return IsControlElement ( ) && IsContentElementCore ( ) ;
Original file line number Diff line number Diff line change @@ -75,7 +75,7 @@ public Rect BoundingRectangle
75
75
76
76
public virtual IRawElementProviderFragmentRoot ? FragmentRoot
77
77
{
78
- get => InvokeSync ( ( ) => GetRoot ( ) ) as IRawElementProviderFragmentRoot ;
78
+ get => InvokeSync ( ( ) => GetRoot ( ) ) ;
79
79
}
80
80
81
81
public virtual IRawElementProviderSimple ? HostRawElementProvider => null ;
@@ -243,20 +243,10 @@ protected void RaiseFocusChanged(AutomationNode? focused)
243
243
( int ) UiaEventId . AutomationFocusChanged ) ;
244
244
}
245
245
246
- private AutomationNode ? GetRoot ( )
246
+ private RootAutomationNode ? GetRoot ( )
247
247
{
248
248
Dispatcher . UIThread . VerifyAccess ( ) ;
249
-
250
- var peer = Peer ;
251
- var parent = peer . GetParent ( ) ;
252
-
253
- while ( peer . GetProvider < AAP . IRootProvider > ( ) is null && parent is object )
254
- {
255
- peer = parent ;
256
- parent = peer . GetParent ( ) ;
257
- }
258
-
259
- return peer is object ? GetOrCreate ( peer ) : null ;
249
+ return GetOrCreate ( Peer . GetVisualRoot ( ) ) as RootAutomationNode ;
260
250
}
261
251
262
252
private void OnPeerChildrenChanged ( object ? sender , EventArgs e )
You can’t perform that action at this time.
0 commit comments