Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Provide API to retrieve the closest MAUI Element to a PlatformView #16330

@PureWeen

Description

@PureWeen

Description

A number of scenarios have come up where, given just a PlatformView we need to be able to get back to the xplat view. This comes up anytime we are watching an event that originates from the platformview and then we need to figure out how to get this message back to an xplat view. This is going to come up a lot with the Keyboard APIs on iOS where we can only wire into the keyboard methods inside the Controller/Layouts. This also comes up a lot on iOS because we can inherit from every single control #10614.

(Public) API Changes

ViewExtentions

Method

API Description
GetVisualTreeElement This will locate the best fit IVisualTreeElement that is associated with this PlatformView. If searchAncestors is false then it will only return the element if the platformView has an exact IVisualTreeElement counterpart.
IVisualTreeElement GetVisualTreeElement(this PlatformView view, bool searchAncestors, [NotNullWhen(true)] out  IVisualTreeElement treeElement)

// searchAncestors defaults to true
IVisualTreeElement GetVisualTreeElement(this PlatformView view)

Usage Scenarios

	public class MauiUIWindow : UIWindow
	{
		public override void DidUpdateFocus(UIFocusUpdateContext context, UIFocusAnimationCoordinator coordinator)
		{
			 context.NextFocusedView.GetVisualTreeElement(false)
                                  .IsFocused = true;

			 context.PreviouslyFocusedView.GetVisualTreeElement(false)
                                  .IsFocused = false;
		}
	}

Backward Compatibility

N/A

Difficulty

Medium

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions